You are here: Re: regex fails stripping alt from img tag « All PHP « IT news, forums, messages
Re: regex fails stripping alt from img tag

Posted by Rik on 08/23/06 14:33

Mike Collins wrote:
> '/<img[^>]*?(alt\s*=\s*[\'"][^\'"]*[\'"])[^>]+>.*/i',
> '$1', $row['text']) . ' (<b>IMG ALT</b>)';
> }
> I do believe the regex looks pretty good. It accounts for single and
> double quotes and spaces around the equals. Any other observations?


I'm curious what the reason for the last .* is. You want to replace
everything up to the end of the line?
Also, once it's matched either a single or double quote, best to stick with
it offcourse, so alt='15" monitor' works:

'/<img #opening tag
[^>]*? #random chars within tag up until next match
(alt\s*=\s* #start of alt attribute
(\'|") #get the quote
([^\2]*) #everything except the used quote
\2) #endquote, end of alt-attribute
[^>]* #allow for excess chars within the tag (why even
match them?)
>.*/ix',

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация