Page 1 of 1

eregi_replace word select only

Posted: Tue Aug 24, 2010 9:47 am
by keno
Hi everyone, I'm trying to convert certain words to links using "eregi_replace". the only problem i seem to be having is when this words fall into a group of words for example;
i want to convert the artist name "eva" to a link, the code converts words like wheneva, how do i make it only convert exact match only..
here is a sample of my code

Code: Select all

$text = eregi_replace('eva', '<a href="Artist/view.php?_id=eva">Eva</a>', $text);

Re: eregi_replace word select only

Posted: Tue Aug 24, 2010 10:02 am
by AbraCadaver
Use preg_* functions, ereg_* functions are deprecated. I think the word boundary will help:

Code: Select all

$text = preg_replace('#\b(eva)\b#i', '<a href="Artist/view.php?_id=eva">Eva</a>', $text);

Re: eregi_replace word select only

Posted: Tue Aug 24, 2010 10:08 am
by keno
AbraCadaver wrote:Use preg_* functions, ereg_* functions are deprecated. I think the word boundary will help:

Code: Select all

$text = preg_replace('#\b(eva)\b#i', '<a href="Artist/view.php?_id=eva">Eva</a>', $text);
Thanks AbraCadaver. You're the best... Its solved my problem like a piece of cake, I'm truly grateful.. I'm gonna be stuck in this forum for sometime. Thanks again