开发者

What is the REGEXP php syntax to change LastName, Firstname to FirstName LastName?

开发者 https://www.devze.com 2022-12-26 18:34 出处:网络
I would like to change the order of names from Last, 开发者_如何学JAVAFirst to First Last.I don\'t know the REGEXP and the php syntax for it.You could just use:

I would like to change the order of names from Last, 开发者_如何学JAVAFirst to First Last. I don't know the REGEXP and the php syntax for it.


You could just use:

$name = "Lastname, Firstname";
$names = explode(", ", $name);
$name = $names[1] . " " . $names[0];


return preg_replace('/^([^,]*),\s*(.*)$/', '$2 $1', $theString);


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号