From 5a0c95a2acf9e1b91d7d502a74dee339ee3d816c Mon Sep 17 00:00:00 2001 From: Philip Olson Date: Thu, 24 Jul 2003 05:07:16 +0000 Subject: [PATCH] Added examples do demonstrate uses with arrays, as well as the count parameter. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@135762 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/strings/functions/str-replace.xml | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/reference/strings/functions/str-replace.xml b/reference/strings/functions/str-replace.xml index 6ce8e5298f..e3bc489824 100644 --- a/reference/strings/functions/str-replace.xml +++ b/reference/strings/functions/str-replace.xml @@ -1,5 +1,5 @@ - + @@ -62,11 +62,27 @@ - <function>str_replace</function> example + <function>str_replace</function> examples "); +// Provides: +$bodytag = str_replace("%body%", "black", ""); + +// Provides: Hll Wrld f PHP +$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); +$onlyconstants = str_replace($vowels, "", "Hello World of PHP"); + +// Provides: 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); + +// Use of the count parameter is available as of PHP 5.0.0 +$str = str_replace("ll", "", "good golly miss molly!", $count); +echo $count; // 2 ?> ]]>