Alt text with preg_replace for accessibility
Hi, I'm creating a text only version of a site and would like to replace inline images with their alt text. In my template files I have: <?php print preg_replace("/<img[^>]+\>/i", "(image) ", $content) ?> which replaces all images with: (image) what code would I need to create output like: (Image description: THE ALT TEXT HERE) and is this best practice? Regards Mark
Hi Mark, You could try this: <?php $pattern = '/<img[^>]*?((alt="(.*?)".*?>)|>)/i'; $replacement = '(Image: $3)'; print preg_replace($pattern, $replacement, $content); ?> However, I do not think this whole approach is needed. Web users who don't want to view images can disable them in their web browser - the job of the web designer is to make sure that the website works well either way. When I'm working on a design I always test with CSS and images disabled. Cheers, Ross. Mark Hope wrote:
Hi,
I'm creating a text only version of a site and would like to replace inline images with their alt text.
In my template files I have: <?php print preg_replace("/<img[^>]+\>/i", "(image) ", $content) ?>
which replaces all images with: (image)
what code would I need to create output like: (Image description: THE ALT TEXT HERE)
and is this best practice?
Regards Mark
_______________________________________________ themes mailing list themes@drupal.org http://lists.drupal.org/mailman/listinfo/themes
Thanks Ross, I'll give the new preg_replace a go. I've already explained to the client that there is no need for a text only site, as the design is xhtml/css and already accessible. She only has limited knowledge of the subject and is being fairly insistent, so I'm implementing it anyway. Cheers Mark On 7 Nov 2006, at 17:20, Ross Kendall wrote:
Hi Mark,
You could try this: <?php $pattern = '/<img[^>]*?((alt="(.*?)".*?>)|>)/i'; $replacement = '(Image: $3)'; print preg_replace($pattern, $replacement, $content); ?>
However, I do not think this whole approach is needed. Web users who don't want to view images can disable them in their web browser - the job of the web designer is to make sure that the website works well either way. When I'm working on a design I always test with CSS and images disabled.
Cheers, Ross.
Mark Hope wrote:
Hi,
I'm creating a text only version of a site and would like to replace inline images with their alt text.
In my template files I have: <?php print preg_replace("/<img[^>]+\>/i", "(image) ", $content) ?>
which replaces all images with: (image)
what code would I need to create output like: (Image description: THE ALT TEXT HERE)
and is this best practice?
Regards Mark
_______________________________________________ themes mailing list themes@drupal.org http://lists.drupal.org/mailman/listinfo/themes
_______________________________________________ themes mailing list themes@drupal.org http://lists.drupal.org/mailman/listinfo/themes
You need to create an anchor or what it's called, it means you can grab a value and can refer to it later. It should work with preg regexes. However I agree with Ross, this isn't really the job of the designer. It's a client side feature and should be handled by the browser. Jakob Mark Hope wrote:
Hi,
I'm creating a text only version of a site and would like to replace inline images with their alt text.
In my template files I have: <?php print preg_replace("/<img[^>]+\>/i", "(image) ", $content) ?>
which replaces all images with: (image)
what code would I need to create output like: (Image description: THE ALT TEXT HERE)
and is this best practice?
Regards Mark
_______________________________________________ themes mailing list themes@drupal.org http://lists.drupal.org/mailman/listinfo/themes
Op dinsdag 7 november 2006 14:59, schreef Mark Hope:
and is this best practice?
No. The theme system *should* be fully (x)html independant. Meaning, that you *should* be able to create a text-only theme without any hacks. note the marks around *should*. However, in your case you should be able to replace over 80% of the image by overriding theme_image. Then there will be another 10% that can be removed by overriding other theme_ functions. All left images that are not extractable with a theme function is a bug. If you find any such in core, please file a bug-report, because you have then found hardcoded HTML, which is considered a bug. Same goes for other modules. Bèr
On 8 Nov 2006, at 15:25, Bèr Kessels wrote:
Op dinsdag 7 november 2006 14:59, schreef Mark Hope:
and is this best practice?
No.
Thanks for the feedback Bèr. The text replacement usage I mentioned was to (mainly) replace inline images inserted with img_assist. The best practice I was asking about was what text to present to the user, having stripped the images using preg_replace. I'm just beginning to understand the power of theming in Drupal, so thanks for your comments below. Mark
The theme system *should* be fully (x)html independant. Meaning, that you *should* be able to create a text-only theme without any hacks.
note the marks around *should*.
However, in your case you should be able to replace over 80% of the image by overriding theme_image. Then there will be another 10% that can be removed by overriding other theme_ functions. All left images that are not extractable with a theme function is a bug. If you find any such in core, please file a bug-report, because you have then found hardcoded HTML, which is considered a bug. Same goes for other modules.
Bèr _______________________________________________ themes mailing list themes@drupal.org http://lists.drupal.org/mailman/listinfo/themes
participants (4)
-
Bèr Kessels -
Jakob Persson -
Mark Hope -
Ross Kendall