Jump to content

Archived

This topic is now archived and is closed to further replies.

yoki

[SOLVED] Reversing a string

Recommended Posts

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.

Share this post


Link to post
Share on other sites

$name = 'lastname, firstname';

 

<?php
  $name = 'lastname, firstname';
  $new = implode(', ',array_reverse(preg_split('/\s*,\s*/',$name,2)));
  print $new;
?>

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.