网络编程 
首页 > 网络编程 > 浏览文章

php str_replace替换指定次数的方法详解

(编辑:jimmy 日期: 2024/5/10 浏览:3 次 )

实例

把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":

<"world","Shanghai","Hello world!");
"htmlcode">
<"blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
"htmlcode">
<"Hello","world");
$replace = array("B");
$arr = array("Hello","world","!");
print_r(str_replace($find,$replace,$arr));
"htmlcode">
<"color: #ff0000">user_order_list 替换为user/order_list

<"htmlcode">
<"color: #0000ff">例子:

<?php 
$str = 'user_order_list'; 
echo str_replace_limit('_', '/', $str, 1); // user/order_list 
$arr = array('abbc','bbac','cbba'); 
$result = str_replace_limit('b', 'B', $arr, 1); 
print_r($result); // Array ( [0] => aBbc [1] => Bbac [2] => cBba ) 
?> 

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

上一篇:thinkPHP实现的省市区三级联动功能示例
下一篇:老生常谈ThinkPHP中的行为扩展和插件(推荐)