If I wanted to take a first name / last name string separated by a comma and change the order, how might I go about that?
last name, firstname
should be changed to
firstname lastname (without the comma)
Thanks.
If I wanted to take a first name / last name string separated by a comma and change the order, how might I go about that?
last name, firstname
should be changed to
firstname lastname (without the comma)
Thanks.
Something like this would work:
string[] names = LastNameFirstName.Split(',');
string FirstNameLastName = names[1] + " " + names[0];
This should do it.
$string = 'last,first';
list($last,$first) = explode( ",", $string );
echo $first . ' ' . $last;
If you wanted to get it done in a spiffy one-liner you could do this:
<?php
$name = "Smith, Dave";
echo implode(' ', array_reverse(explode(',', $name)));
$string = 'last , first';
list($last,$first) = preg_split("/\s+,\s+/",$string);
$s = preg_split("/[, ]/",$string);
print implode(" ", array($s[0], end($s)));
print implode(" ", array($last,$first));
print preg_replace("/(\w+)\s+,\s+(\w+)/","$2 $1", $string);