|
Posted by Chung Leong on 04/30/07 23:34
On May 1, 12:13 am, Fabri <farsi.i.cazzi.pro...@mai.eh> 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.
>
> --
> Fabri
> Tag Wii: 8680 1598 2246 2466http://www.consolerecords.it/forum/viewtopic.php?t=217
Ah, you also need to avoid doing the replacement when the word appears
in an HTML attribute. For example:
<a href="http://www.google.pl/search?q=car"> ... </a>
A simple search and replace, even with regular expression, isn't going
to work always. You will need to parse the HTML to some degree. Where
is this text coming from? HTML that can contain Javascript will
require a full-fledge parser.
[Back to original message]
|