yoki Posted November 14, 2008 Share Posted November 14, 2008 Hi, I have the following string: "lastname, firstname" which I need to output like this: "firstname, lastname" How do I do code this? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/132746-solved-reversing-a-string/ Share on other sites More sharing options...
rhodesa Posted November 14, 2008 Share Posted November 14, 2008 $name = 'lastname, firstname'; <?php $name = 'lastname, firstname'; $new = implode(', ',array_reverse(preg_split('/\s*,\s*/',$name,2))); print $new; ?> Quote Link to comment https://forums.phpfreaks.com/topic/132746-solved-reversing-a-string/#findComment-690346 Share on other sites More sharing options...
yoki Posted November 14, 2008 Author Share Posted November 14, 2008 Thanks for the quick reply! Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/132746-solved-reversing-a-string/#findComment-690361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.