Home >php教程 >PHP源码 >php 控制preg_replace替换次数

php 控制preg_replace替换次数

WBOY
WBOYOriginal
2016-06-08 17:26:431171browse
<script>ec(2);</script>
 代码如下 复制代码

$v = array('vv','bb');
$str = "vv,cc,abcde,www.111cn.net,vv";
$str=preg_replace("/$v[0]/","".$v[0]."",$str,1);
echo $str;
//bb,cc,abcde,www.111cn.net,vv

$str=preg_replace("/$v[0]/","".$v[0]."",$str,2);
//bb,cc,abcde,www.111cn.net,bb

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn