[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 bJoe 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 bJoe/b Cougar bDoe/b. So: $searched = Joe Doe; $original = Joe Cougar Doe; $final = bJoe/b Cougar bDoe/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
RE: [PHP] Replacing non exact strings
Julio, Try this $search = Joe Doe; $original = Joe Cougar Doe; $final = bJoe/b Cougar bDoe/b; $terms = explode( ,$search); for($i=0; $icount($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 [EMAIL PROTECTED] http://www.chieftain.com -Original Message- From: Julio Nobrega Trabalhando [mailto:[EMAIL PROTECTED]] Sent: Friday, May 03, 2002 8:36 AM To: [EMAIL PROTECTED] 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 bJoe 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 bJoe/b Cougar bDoe/b. So: $searched = Joe Doe; $original = Joe Cougar Doe; $final = bJoe/b Cougar bDoe/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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Replacing non exact strings
On 3 May 2002 at 11:36, Julio Nobrega Trabalhando wrote: $searched = Joe Doe; $original = Joe Cougar Doe; $final = bJoe/b Cougar bDoe/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. Split $searched using explode, then do the replace on each element of the resulting array... $searched = Joe Doe; $original = Joe Cougar Doe; $searchedwords = explode( , $searched); $final = $original; foreach ($searchedwords as $word) { $final = eregi_replace($word, b$word/b, $final); } $final = bJoe/b Cougar bDoe/b; -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Replacing non exact strings
Thanks Brian, it's working! -- Julio Nobrega. Brian Paulson [EMAIL PROTECTED] wrote in message 005101c1f2af$fa59eb00$89010a0a@bpaulson">news:005101c1f2af$fa59eb00$89010a0a@bpaulson... Julio, Try this -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php