eregi_replace word select only

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keno
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2010 9:34 am

eregi_replace word select only

Post 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);
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: eregi_replace word select only

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
keno
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2010 9:34 am

Re: eregi_replace word select only

Post 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
Post Reply