Hi,
I actually work on a function that parse names coming from a database. The purpose of the function is just reverse the last name and first name order, the original string is comma (and optional space) separated.
Examples :
Smith, Rob becomes Rob Smith
Mr Davidson becomes Mr Davidson
Barry,Betty becomes Betty Barry
I end by found two ways to do it but which is the more efficient ?
PHP Code:
// 1rst way
function parseName($name)
{
if(ereg(",", $name)) {
return preg_replace("/(.*),\\s?(.*)/", "\\\\2 \\\\1", $name);
}
return $name;
}
//2nd way
function parseName($name)
{
return join(" ", array_reverse(split(", ?", $name)));
}
Thanks in advance for any suggestion