php replace
// Génère : <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
// Génère : Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// Génère : You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
// Génère : good goy miss moy
$str = str_replace("ll", "", "good golly miss molly!", $count);
echo $count;
<?php
// This is the string we will search through
$stringToSearch = "Hello World";
// This is the string we are trying to find
$stringWeAreLookingFor = "World";
// If we find the string we are looking for, we will replace
// it with this string
$replaceString = "PHP";
// We use the str_replace method to replace a substring in php
$newString = str_replace( $stringWeAreLookingFor, $replaceString, $stringToSearch );
// The newString variable now contains the string "Hello PHP"
// Please note this search IS case sensitive. Use str_ireplace()
// case in-sensitive searches.
// This function can also be used with an array of strings
$stringArray = [ "Test", "Test", "Goose" ];
$stringWeAreLookingFor = "Test";
$replaceString = "Duck";
$newArray = str_replace( $stringWeAreLookingFor, $replaceString, $stringArray );
// The newArray variable will now contain [ "Duck", "Duck", "Goose" ]
?>