最新下载
热门教程
- 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";
$str1=array(
array('111com.net','/er.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
$str=preg_replace("/$nkeys[0]/","",$str,1); $count++;
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));
}
相关文章
- JPress v3.0 alpha.1 06-06
- 后台整合包精简版-servlet_DBC v2.0 06-06
- jspgou网店系统 店中店版 v6.1.1 06-06
- MongooseJS v5.4.1.7 06-06
- jboot v2.0-rc.8 全新版 开源框架 06-06
- ECharts v4.2.1 rc1 商业产品图表库 06-06