1

My database contains full names, for example :

VernonClemans

SusanPostell

RonaldGutkowski

without any space or delimiter. I want to split them into first and last name

All full names have the same format: 1 word with 2 uppercase letters.

How can I split them?

gvlasov
  • 18,638
  • 21
  • 74
  • 110

1 Answers1

1
<pre>
<?php
  $string = "VernonClemans\nSusanPostell\nRonaldGutkowski";
  foreach(explode("\n", $string) as $name) {
   list($first_name, $last_name) = preg_split('/(?<=\\w)(?=[A-Z])/', $name);
   print "First Name: $first_name \nLast Name: $last_name\n";
  }
?>
</pre>
Eugen
  • 1,356
  • 12
  • 15