Friday, October 24, 2025
HomeLanguagesPHP mb_ereg_replace() Function

PHP mb_ereg_replace() Function

The mb_ereg_replace() is an inbuilt function in PHP that is used to search & replace a string using the regular expression. This function is similar to the preg_match() but works on the multibyte string.

Syntax:

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

Parameters: The following function accepts four parameters that are described below.

  • $pattern: This parameter used regular expression. It must be a valid regular expression.
  • $replacement: The string that is replaced according to the pattern.
  • $string:  This is the string where we search our pattern.
  • $option:  This is an optional parameter that is used for the matching option. Example ‘i’ for case insensitive and ‘m’ for multiline characters or ‘s’ for matching across lines.

Return Values: This function returns the resulting string if the function successfully executes otherwise it will return “false” on error.

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

PHP




<?php
$pattern = "[g]";
$replace = "G";
$return = mb_ereg_replace($pattern, $replace, "neveropen");
var_export($return);
?>


Output:

'neveropen'   

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

PHP




<?php
$pattern = "[neveropen]";
$replace = "Geeks";
$return = mb_ereg_replace($pattern, $replace, "neveropen");
var_export($return);   
?>


Output:

'GeeksGeeksGeeksGeeksneveropenGeeksGeeksGeeksGeeks' 

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS