最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
str_replace只替换一次代码
时间:2022-07-02 09:14:32 编辑:袖梨 来源:一聚教程网
str_replace只替换一次代码
$str ="中国|111com.net|111com.net|111com.net|jkldajfklda李好,美女,世界中国中国中国
中国中国abc,dee"; href=http://111com.net.com".$nkeys[1]." target=_blank >".$nkeys [0]."
$str1=array(
array('111com.net','/phper.html'),
array('中国','/phper.html'),
array('李好','/phper.html'),
array('dee','/phper.html'),
array('abc','/phper.html')
);
//$temp = str_replace('111com.net','前程似锦',$str,$a);
$count =0;
foreach($str1 as $nkeys){
if(strpos($str,$nkeys[0]) ){
if( $count <=1 ){
$str=preg_replace("/$nkeys[0]/","
continue ;
}
}
}
echo $count,$str;
//preg_replace(【要替换的关键字】, 【替换为的关键字】, 【原字符串】, 【替换次数
】);
//方法二:
function str_replace_once($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
相关文章
- 火影忍者怎么获得大招 05-03
- 星际战甲新手什么刀好 05-03
- 文明6秦始皇金字塔怎么加速 05-03
- 全民奇迹2龙骸巨剑怎么获得 05-03
- 星露谷物语鲟鱼怎么获得 05-03
- 长安幻想怎么转职 05-03