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 Mike Collins on 08/23/06 20:09

On Wed, 23 Aug 2006 21:56:09 +0200, "Rik" <luiheidsgoeroe@hotmail.com>
wrote:

>> preg_replace(
>> '/<img #comments are cool
>> [^>]*?
>> (
>> alt\s*=\s*
>> (\'|") #match the quote
>> ([^\2]*?) #get alt content; dont be greedy
>> \2 #use matched quote
>> )
>> .* #chop and toss
>> /ix
>> ',
>> '$1', $row['text']) . ' (<b>IMG ALT</b>)';
>>
>> The tag below won't ruin my day but the results won't be pretty. Tried
>> the m modifier, no dice.
>>
>> <img src="/img/l_eng.png"
>> alt=""
>> width="27"
>> height="20"
>> />
>
>Well, exactly what do you want with alt="", no match, an empty string?

I can assign anything to it. The way I'm using it here I just echo

alt="" (<b>IMG ALT</b>)
alt="whatever, either is fine" (<b>IMG ALT</b>)

If I scrape links off a page with snoopy and output them to a browser
broken image links annoy me. Thanks to you, I'm smiling.

 

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

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