En PHP, comment remplacer les occurrences d'une sous-chaîne dans une chaîne de caractères ?
La fonction PHP str_replace($substring, $replace, $string) retourne la chaîne $string après avoir remplacer toutes les occurrences de $substring par $replace. Voici un exemple:
// Chaîne originale
$phrase = "To be or not to be.";
// remplace 'be' par 'eat' dans la chaîne originale
$newPhrase = str_replace('be', 'eat', $phrase);
// Affiche : To eat or not to eat.
echo $newPhrase;
La fonction PHP str_replace($substring, $replace, $string) retourne la chaîne $string après avoir remplacer toutes les occurrences de $substring par $replace. Voici un exemple:
// Chaîne originale
$phrase = "To be or not to be.";
// remplace 'be' par 'eat' dans la chaîne originale
$newPhrase = str_replace('be', 'eat', $phrase);
// Affiche : To eat or not to eat.
echo $newPhrase;
La fonction PHP str_replace($substring, $replace, $string) retourne la chaîne $string après avoir remplacer toutes les occurrences de $substring par $replace. Voici un exemple:
// Chaîne originale
$phrase = "To be or not to be.";
// remplace 'be' par 'eat' dans la chaîne originale
$newPhrase = str_replace('be', 'eat', $phrase);
// Affiche : To eat or not to eat.
echo $newPhrase;
| # | ID | Query | URL | Count |
|---|