Open In App

PHP mb_eregi_replace() Function

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:

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
$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
$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

Article Tags :