Pick up only the user's first and last name

2

Dear colleagues.

How can I get a user's first and last name? I often use it as follows:

$nomeUsuario = 'Francisco de Assis';
list($nome,$sobrenome) = explode(' ',$nomeUsuario);

But this way I would get Francisco from and I would really like to take Francisco Assis.

Would anyone have any idea how I would do this?

Thank you!

    
asked by anonymous 10.06.2015 / 21:57

1 answer

4

Try it out

$partes = explode(' ', $nomeUsuario);
$primeiroNome = array_shift($partes);
$ultimoNome = array_pop($partes);
  • array_shift - remove and return the first value of the array.
  • array_pop - remove and return the last value of the array.
10.06.2015 / 22:01