php str_replace函数(可限制替换个数)本文章主要是介绍str_replace函数替换单个字符,与替换数据,以及指定str_replace替换的次数,最后一个替换次数是很有用的特别是在seo优化方法面哦。
php教程 str_replace函数(可限制替换个数)
本文章主要是介绍str_replace函数替换单个字符,与替换数据,以及指定str_replace替换的次数,最后一个替换次数是很有用的特别是在seo教程优化方法面哦。
/mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
个函数返回一个字符串或在出现问题的所有搜索给定的数组替换值替换。
如果你不喜欢需要更换的规则(如正则表达式),你应该始终使用此函数,而不是ereg_replace()或preg_replace函数()。
*/
// 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;
//利用str_replace函数指定替换次数
一个功能强大的B2B与B2C的购物平台,除了原本OSC功能外,增加更新的功能: 一、 取消了register_globals必须开启的限制 二、 將HTML程式碼与PHP程式碼完全分离,採用了smarty 樣板引擎 三、 每支档案includes所需函数与资料库连结,使的网页显示速度明显提升 四、 检视、购买商品群组权限设定 五、 十八岁以下禁购机制 六、 折价券购物抵扣机制 七、 礼券购物机制
$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
$tos = strtolower($v[0]);
$str=preg_replace("/$tos/","".$v[2]."",$str,1);
$count++;
continue;
}
}
}
return $str;
}
?>










