Here is the problem : I want to split a string to have the name and the first name, but my two variable are empty and i don’t understant why… Can someone help me ? This my code :
$nom_aut1 = "";
$prenom_aut2 = "";
//$auteur1 is already initialized
for ($i = 0; $i < strlen($auteur1); ++$i)
{
if ($auteur1[$i] != ' ') continue;
for ($j = 0; $j < $i; ++$j)
{
$nom_aut1 .= $auteur[$j];
}
for ($j = $i+1; $j < strlen($auteur1); ++$j)
{
$nom_aut1 .= $auteur1[$j];
}
break;
}
echo '"'.$nom_aut1.'.'.$prenom_aut1.'"';
Thank you 🙂
Do you want to split a name into first and last name based on a space? Why not just do this:
If
$name = "Hello World"$nameswill be an array such thatThis way, if there is a middle name, you can get that as well.
You can do it this way:
So, if
$name = "Hello Foo Bar World"