On 3 May 2002 at 11:36, Julio Nobrega Trabalhando wrote:
> $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.

Split $searched using explode, then do the replace on each element of the resulting 

$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 = "<b>Joe</b> Cougar <b>Doe</b>";


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to