当前位置: 首页> 函数类别大全> str_ireplace

str_ireplace

str_replace的不区分大小写的版本
名称:str_ireplace
分类:字符串
所属语言:php
一句话介绍:替换字符串中的一些字符(对大小写不敏感)。

str_ireplace 函数

适用PHP版本

PHP 4.0.0 及以上版本

函数说明

str_ireplace 函数用于在字符串中查找并替换所有出现的子串(不区分大小写)。该函数是 str_replace 函数的大小写不敏感版本。

函数语法

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

参数

  • $search:要查找的子串或数组。
  • $replace:替换为的内容,可以是单一字符串或者数组。
  • $subject:输入的字符串或字符串数组,表示要进行查找和替换的对象。
  • $count(可选):一个引用变量,如果提供,它会接收替换操作的次数。

返回值

返回一个经过替换后的字符串,如果提供了数组作为输入,则返回数组形式的替换结果。如果没有进行替换,返回原始的输入字符串。

示例

    <?php
      $input = "Hello world! Welcome to PHP programming.";
      $output = str_ireplace("hello", "Hi", $input);
      echo $output;
    ?>
  

示例代码说明:这段代码将输入字符串中的 "Hello"(不区分大小写)替换为 "Hi",输出的结果是:Hi world! Welcome to PHP programming.

更多示例

    <?php
      $input = "This is a test. test test test.";
      $output = str_ireplace("test", "example", $input, $count);
      echo $output;  // 输出:This is a example. example example example.
      echo "替换次数:$count";  // 输出:替换次数:4
    ?>
  

示例代码说明:这段代码将所有的 "test"(不区分大小写)替换为 "example",并且通过 $count 变量显示替换发生的次数。

同类函数
  • 计算字符串的md5哈希值 md5

    md5

    计算字符串的md5哈希值
  • 随机打乱一个字符串 str_shuffle

    str_shuffle

    随机打乱一个字符串
  • 输出一个字符串 print

    print

    输出一个字符串
  • 根据指定格式解析输入的字符 sscanf

    sscanf

    根据指定格式解析输入的字符
  • 将字符串转化为小写 strtolower

    strtolower

    将字符串转化为小写
  • 二进制安全字符串比较 strcmp

    strcmp

    二进制安全字符串比较
  • 将所有适用的字符转换为HTML实体-将字符转换为 HTML 转义字符 htmlentities

    htmlentities

    将所有适用的字符转换为HTML实体-将字
  • 对字符串执行rot13转换 str_rot13

    str_rot13

    对字符串执行rot13转换
热门文章