开发者

flipping the names around in php

开发者 https://www.devze.com 2023-03-09 01:37 出处:网络
ok so i have a user field that has the user enter the full name and i need to flip the names around $pieces = explode(\" \", $_POST[\'realname\']);

ok so i have a user field that has the user enter the full name and i need to flip the names around

 $pieces = explode(" ", $_POST['realname']);
 name = stripslashes($pieces[1] . "-" . $pieces[0]);

but the problem is that if they type in the field

i need the final output as jones-mark for sake of the requirements or if there is only m开发者_运维知识库ark then i need mark

mark jones

all is well but if they type

mark 

then the output is

-mark

im sure there is a better way to do this


implode("-",array_reverse($pieces))

0

精彩评论

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