Reply to Re: Complex replace in php 4

Your name:

Reply:


Posted by gosha bine on 05/02/07 08:02

On 01.05.2007 00:13 Fabri wrote:
> I searched and tried to develop (with no luck) a function to do the
> following:
>
>
> I have a string that may be:
>
> "Le'ts go to <a href="my.htm">my car</a>. Tomorrow I'll have to buy a
> new car. My new car is <em>red</em>! Please don't think to be in Nascar!!"
>
>
> What I have to do is replace occurences of "car" with <a
> href="/...">car</a> BUT in these cases:
>
> - if there is already a wrapped link
> - if car is part of another word
>
>
> Also, I'm using php4 so I can't use str_ireplace for case insensitive
> replace.
>
> Can you help me?
>
> Regards.
>

Well, over 30 hours and still no correct answer... weird ;)

How about this:


$text = <<<EE
"Le'ts go to <a href="my.htm">my car</a>.
Tomorrow I'll have to buy a
new car. My new car is <em>red</em>!
Please don't think to be in Nascar!!"
EE;

echo preg_replace(
'~\bcar\b(?![^<>]*</a>)~i',
"<a href='zzz'>$0</a>",
$text);

If you need comments, feel free to ask.



--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[Back to original 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

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