Replacing non exact strings
| From: | Julio Nobrega Trabalhando | Date: | Fri, 03 May 2002 14:36:22 +0000 |
| Subject: | Replacing non exact strings | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-95898@lists.php.net to get a copy of this message | ||
Hi List,
Imagine a form where user can search for clients using a 'name' field.
When submitted, there's a result page, linking results to another page with
the client information.
I need to make the terms inputted at the form bold when they appear at the
client information page. Problem is: When someone searchs for "Joe Doe", and
the client's name is "Joe Doe", I can make it "<b>Joe Doe</b>".
But when the name is "Joe Cougar Doe", I can't bold it (parts Joe && Doe)
because there's this "Cougar" in the middle. The result I am looking for is
"<b>Joe</b> Cougar <b>Doe</b>".
So:
$searched = "Joe Doe";
$original = "Joe Cougar Doe";
$final = "<b>Joe</b> Cougar <b>Doe</b>";
Any ideas about how can I achieve this result? I am currently using
eregi_replace($searched, "<b>$searched</b>", $original), so that's why it
only accepts the whole string.
Thanks a lot,
Julio Nobrega.