Bu işlev dizge dizgesi içinde şablon düzenli ifadesini arar ve eşleşen metnin yerine yenisi'ni yerleştirir. <?php
$string = "This is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "\\1was", $string);
echo ereg_replace("(( )is)", "\\2was", $string);
?> konu dizgesi içindeki eski dizgelerinin her birini yeni dizgesiyle değiştirerek elde edilen dizi veya dizgeyi döndürür. <?php
// Sonuç: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
// Sonuç: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// Sonuç: 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);
// sağlanan: 2
$str = str_replace("ll", "", "good golly miss molly!", $count);
echo $count;
?>