无为清净楼资源网 Design By www.qnjia.com

下面通过本文给大家分享PHP字符串替换str_replace()函数4种用法,具体内容如下所示:

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

该函数返回一个字符串或者数组。该字符串或数组是将subject中全部的search都被replace替换之后的结果。

1、$search,要替换的字符串,或数组

2、$replace,被用来替换的字符串或数组

3、$subject,被查询的字符串或数组

4、$count,可选,如果被指定,将为设置为替换的次数

5、返回值:该函数返回替换后的数组或者字符串(新生成的)

<"red","black","red green yellow pink purple");
  echo $str1."";  //输出结果为black green yellow pink purple
"blue","red","green","yellow");
  $str1 = str_replace("red","pink",$arr,$i);
  print_r($str1);
"banana","orange");
  $arr2 = array("pitaya","tomato");
  $con_arr = array("apple","orange","banana","grape");
  $con_rep = str_replace($arr1,$arr2,$con_arr,$count);
  print_r($con_rep);
"banana","grape");
  $replace = "tomato";
  $arr = array("banana","apple","orange","grape");
  $new_arr = str_replace($search,$replace,$arr,$count);
  print_r($new_arr);
"color: #ff0000">总结

以上所述是小编给大家介绍的PHP字符串替换str_replace()函数四种用法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

标签:
str,replace函数,php,str,replace函数

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com