tags:

views:

37

answers:

3

I need to create a php search function for names and need to change LastName, FirstName into LastName..FirstName to search the database. I don't know if this helps, but the string will originally be in the form a variable ($Client).

I need the syntax for the three statements that find the string, matches, and makes the changes.

+2  A: 
str_replace(', ', '..', $Client);
Coronatus
+1  A: 

Is

$name = str_replace(", ", "..", $name);

out of the question?

Matti Virkkunen
+2  A: 

If you'd like to use a regular expression:

$client = preg_replace('/,\s+/', '..', $client);

Regular expression explanation

,     ',' literal comma
\s+   followed by 1 or more whitespace characaters

All that being said, str_replace can do the trick if you will always have "Doe, John" (with one space)

macek