For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2006 > regular expression









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regular expression
olo

2006-10-19, 7:56 am

Hi

I need to change some text into hyperlink. Something like that:

$mytext = eregi_replace('(myword)', '<a href="somelink">\\1</a>', $mytext);

But there is a problem when $mytext containg string like:

'check it out <a href="someotherlink">somtething myword something</a>'

because i'll got:

'check it out <a href="someotherlink">something <a
href="somelink">myword</a> something</a>'

how can i fix that?

--
pozdrawiam!

http://webtrunki.pl - piwa, wina, wódki, domowe wyroby
ZAPRASZAMY!!
Koncept

2006-10-20, 6:56 pm

In article <eh7krt$h9q$1@inews.gazeta.pl>, olo
<olo69maupapocztafm@nospam.com> wrote:

> Hi
>
> I need to change some text into hyperlink. Something like that:
>
> $mytext = eregi_replace('(myword)', '<a href="somelink">\\1</a>', $mytext);
>
> But there is a problem when $mytext containg string like:
>
> 'check it out <a href="someotherlink">somtething myword something</a>'
>
> because i'll got:
>
> 'check it out <a href="someotherlink">something <a
> href="somelink">myword</a> something</a>'
>
> how can i fix that?


If I understand this, you want to take instances of "myword" and wrap
it within a hyperlink correct? Well if so, your find/replace is working
exactly as you asked it to. Is the problem that you need to fix pattern
substitutions when already enclosed within an anchor element?

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com