PHP str_replace function (can limit the number of replacements) This article mainly introduces the Str_replace function to replace a single character, and replace the data, as well as specify the number of Str_replace replacements, the last replacement number is very useful especially in SEO optimization method surface Oh.
PHP Tutorial Str_replace function (can limit the number of replacements)
This article mainly introduces the Str_replace function to replace a single character, with the replacement data, as well as specifying the number of Str_replace replacements, the last replacement count is useful especially in SEO Tutorial optimization method Surface Oh.
/mixed str_replace (mixed $search, mixed $replace, mixed $subject [, int & $count])
A function returns a string or replaces the given array substitution value in all occurrences of the problem.
If you don't like rules that need to be replaced (such as regular expressions), you should always use this function instead of the ereg_replace () or Preg_replace function ().
*/
Provides:
$bodytag = Str_replace ("%body%", "Black", "" ");
Provides:hll Wrld F PHP
$vowels = Array ("A", "E", "I", "O", "U", "a", "E", "I", "O", "U");
$onlyconsonants = 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);
Provides:2
$str = Str_replace ("ll", "" "," Good Golly Miss Molly! ", $count);
Echo $count;
Use the Str_replace function to specify the number of replacements
$array = Array (
Array (0,1,2)
);
function keywords ($str, $array)
{
$count = 0;
foreach ($array as $v) {
if (Strstr ($str, Strtolower ($v [0]))!==false) {
if ($count <=3) {
$tos = Strtolower ($v [0]);
$str =preg_replace ("/$tos/", "". $v [2]. ", $STR, 1);
$count + +;
Continue
}
}
}
return $str;
}
?>
http://www.bkjia.com/PHPjc/445401.html www.bkjia.com true http://www.bkjia.com/PHPjc/445401.html techarticle php str_replace function (can limit the number of replacements) This article is mainly about the Str_replace function to replace a single character, and replace the data, and specify the number of times the str_replace substitution, the last replacement ...