. ou la fonction implode
$variable1 = 'Professeur';
$variable2 = 'Dumbledore';
$chaines1 = $variable1 . ' ' . $variable2;
$chaines2 = implode(array(" Albus", ' Percival', "Wulfric"));
$chaines3 = implode(' ; ',array(" Albus", ' Percival', "Wulfric"));
echo implode(array("<p>",$chaines1,"<br />", $chaines2,"<br />",$chaines3,"</p>"));
$implodeCh = implode(array("<p>",$chaines1,"<br />", $chaines2,"<br />",$chaines3,"</p>"));
Résultat :
Professeur Dumbledore
AlbusPercivalWulfric
Albus ; Percival ; Wulfric
explode
$stringArray = explode(';', $chaines3);
foreach($stringArray as $ch) {
echo "*".$ch."*"; // pas de traitement des espaces
}
echo "<br />";
foreach($stringArray as $ch) {
echo "*".trim($ch)."*"; // suppression des espaces en début et fin de chaine
}
Résultat :strlen, strpos, substr, str_replace, str_rot13, ...