views:

54

answers:

3

I would like to change the order of names from Last, First to First Last. I don't know the REGEXP and the php syntax for it.

+3  A: 
return preg_replace('/^([^,]*),\s*(.*)$/', '$2 $1', $theString);
KennyTM
+3  A: 

You could just use:

$name = "Lastname, Firstname";
$names = explode(", ", $name);
$name = $names[1] . " " . $names[0];
Lex
To a noobie, something that works seems like magic. Thanks!
ggg
A: 

I hate regular expressions.. You could always do something like

implode(' ',array_reverse(explode(' ,',$string)))

But I'm probably only suggesting that because it's the more intuitive way in Ruby, which I've recently dropped php for :)

Jeriko