Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2013/12/29 4:41:15
php之str_replace_php资料_编程技术

php之str_replace_php资料_编程技术-你的首页-uuhomepage.com
字符串取代。

  语法: string str_replace(string needle, string str, string haystack);

  返回值: 字符串

  函数种类: 资料处理

  内容说明

  本函数将字符串 str 代入 haystack 字符串中,将所有的 needle 置换成 str。mlevine@adtraq.com (11-Apr-1999) 指出在 PHP 3.0.7 版

  本函数有些 bug,而 nadeem@bleh.org (05-Jun-1999) 补充在 PHP 3.0.8 版本函数就回复正常了。

  使用范例

  下例将 %body% 以 black 取代

  
  $bodytag = str_replace("%body%", "black", "");

  echo $bodytag;

  ?>

  参考

  ereg_replace()

  提示和注释

  注释:该函数对大小写敏感。请使用 str_ireplace() 执行对大小写不敏感的搜索。

  注释:该函数是二进制安全的。

  例子

  例子 1

  
  echo str_replace("world","John","Hello world!");

  ?>输出:

  Hello John!例子 2

  在本例中,我们将演示带有数组和 count 变量的 str_replace() 函数:

  
  $arr = array("blue","red","green","yellow");

  print_r(str_replace("red","pink",$arr,$i));

  echo "Replacements: $i";

  ?>输出:

  Array

  (

  [0] => blue

  [1] => pink

  [2] => green

  [3] => yellow

  )

  Replacements: 1例子 3

  
  $find = array("Hello","world");

  $replace = array("B");

  $arr = array("Hello","world","!");

  print_r(str_replace($find,$replace,$arr));

  ?>输出:

  Array

  (

  [0] => B

  [1] =>

  [2] => !

  )






If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759