RE: [PHP] Replacing non exact strings

From: Date: Fri, 03 May 2002 14:36:50 +0000
Subject: RE: [PHP] Replacing non exact strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-95902@lists.php.net to get a copy of this message
Julio, Try this $search = "Joe Doe"; $original = "Joe Cougar Doe"; $final = "<b>Joe</b> Cougar <b>Doe</b>"; $terms = explode(" ",$search); for($i=0; $i<count($terms); $i++) { $original = eregi_replace($terms[$i], "<b>".$terms[$i]."</b>", $original); } echo $original; Should get you started. Thank You Brian Paulson Sr. Web Developer bpaulson@chieftain.com http://www.chieftain.com -----Original Message----- From: Julio Nobrega Trabalhando [mailto:inerte@hotmail.com] Sent: Friday, May 03, 2002 8:36 AM To: php-general@lists.php.net Subject: [PHP] Replacing non exact strings 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#95902) next »