Horje
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:

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




Reffered: https://www.geeksforgeeks.org


PHP

Related
PHP mb_http_input() Function PHP mb_http_input() Function
PHP mb_ord() Function PHP mb_ord() Function
PHP func_num_args() Function PHP func_num_args() Function
PHP error_clear_last() Function PHP error_clear_last() Function
PHP restore_error_handler() Function PHP restore_error_handler() Function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15