[themes] Alt text with preg_replace for accessibility

Ross Kendall drupal at rosskendall.com
Tue Nov 7 17:20:53 UTC 2006


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 at drupal.org
> http://lists.drupal.org/mailman/listinfo/themes
>   


More information about the themes mailing list