Open In App

PHP mb_eregi_replace() Function

Last Updated : 31 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mb_eregi_replace() is an inbuilt function in PHP that is used to perform the replacement of regular expression characters. It is a case-insensitive regular expression search and replace with multi-byte character support.

Syntax:

mb_eregi_replace(
    string $pattern,
    string $replacement,
    string $string,
    ?string $options = null
): string|false|null

Parameters: This function accepts four parameters that are described below:

  • $pattern: This parameter specifies the regular expression pattern to search for.
  • $replacement: This parameter specifies the string that is to be replaced.
  • $string: This is the string where we search and replace the string.
  • $options:  This is the optional parameter with some following flags: ‘m’ (multiline matching), ‘s’ (single-line matching), ‘r’ (replace backreferences), and ‘i’ (case-insensitive matching).

Return Value: This function returns the resultant string, in case of not getting an error, otherwise return false. Also, null will be returned in the case when the string is not valid for the current encoding.

Example 1: The following program demonstrates the mb_eregi_replace()  function.

PHP




<?php
$string = "GFG";
$pattern = "[G]";
$replacement = "T";
$result = mb_eregi_replace($pattern, $replacement, $string);
echo $result;      
?>


Output:

TFT 

Example 2: The following program demonstrates the mb_eregi_replace() function.

PHP




<?php
$string = "water work word";
$pattern = "[W]";
$replacement = "r";
$result = mb_eregi_replace($pattern,$replacement, $string);
echo $result;
?>


Output:

water work word  

Reference: https://www.php.net/manual/en/function.mb-eregi-replace.php


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads