编程爱好者之家
//字符串替换函数 function replaceString($search,$replace,$content,$limit=-1){ if(is_array($search)){ foreach ($search as $k=>$v){ $search[$k]='`'.preg_quote($search[$k],'`').'`'; } }else{ $search='`'.preg_quote($search,'`').'`'; } //把描述去掉 $content=preg_replace("/alt=([^ >]+)/is",'',$content); return preg_replace($search,$replace,$content,$limit); }
如果是想替换一次$limit设置为1,不限制次数就设置为-1