当前位置: 首页> 函数类别大全> 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 变量显示替换发生的次数。

同类函数
  • 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew) hebrev

    hebrev

    将逻辑顺序希伯来文(logical-He
  • 计算两个字符串之间的编辑距离 levenshtein

    levenshtein

    计算两个字符串之间的编辑距离
  • 解码一个 uuencode 编码的字符串 convert_uudecode

    convert_uudecode

    解码一个uuencode编码的字符串
  • 使用 uuencode 编码一个字符串 convert_uuencode

    convert_uuencode

    使用uuencode编码一个字符串
  • 翻译字符或替换子字符串-转换指定字符 strtr

    strtr

    翻译字符或替换子字符串-转换指定字符
  • 单向字符串散列 crypt

    crypt

    单向字符串散列
  • 将二进制数据转换为十六进制表示 bin2hex

    bin2hex

    将二进制数据转换为十六进制表示
  • 以千位分隔符方式格式化一个数字 number_format

    number_format

    以千位分隔符方式格式化一个数字
热门文章