Current Location: Home> Function Categories> mb_eregi_replace

mb_eregi_replace

Multibyte-supported replacement regular expressions, ignoring upper and lower case
Name:mb_eregi_replace
Category:Multi-byte string
Programming Language:php
One-line Description:A multibyte string function for performing case-insensitive regular expression replacement operations

Function name: mb_eregi_replace()

Function description: The mb_eregi_replace() function is a multibyte string function that performs case-insensitive regular expression replacement operations. It looks for matching parts in the string by using regular expression patterns and replaces them with the specified replacement string.

Function signature: string mb_eregi_replace ( string $pattern , string $replacement , string $string [, string $option = "msri" ] )

parameter:

  • $pattern: A string representing a regular expression pattern that matches parts of a string.
  • $replacement: A string that represents the content to be used to replace the matching part.
  • $string: A string that represents the target string to perform the replacement operation.
  • $option (optional): A string representing regular expression options. The default is "msri", which means multi-line, case-insensitive, recursive, and UTF-8 encoding.

Return value: The result string after performing the replacement operation.

Notes:

  • This function requires support for mbstring extension. If the mbstring extension is not enabled, the function will not be used.
  • Unlike the traditional eregi_replace() function, the mb_eregi_replace() function is case-insensitive.

Example:

 $string = "Hello, PHP!"; $pattern = "php"; $replacement = "World"; $result = mb_eregi_replace($pattern, $replacement, $string); echo $result; // 输出: Hello, World!

In the example above, we use the mb_eregi_replace() function to replace "php" in the string with "World". Since this function is case-insensitive, no matter whether "php" in the string is uppercase or lowercase, it will be replaced correctly. Finally, we output the result string "Hello, World!" through the echo statement.