PHP mb_ereg_search() Function
Last Updated :
23 Jul, 2025
The mb_ereg_search() is a PHP function used to search & match for a regular expression pattern in a string using multi-byte characters. It is similar to preg_match() but works with multi-byte characters.
Syntax:
mb_ereg_search(?string $pattern = null, ?string $options = null): bool
Parameters: This function accepts the two parameters that are described below:
- pattern: A regular expression pattern search for. It must be a valid regular expression for searching for a specific pattern in the string.
- options: This is an optional parameter. A string that specifies the search options.
Return Value: This function returns "true" if the multibyte string matches with a given regular expression otherwise returns "false".
Example 1: The following code demonstrates the mb_ereg_search() function.
PHP
<?php
$string = "Hello, world!";
mb_regex_encoding("UTF-8");
mb_ereg_search_init($string);
if (mb_ereg_search("world")) {
echo "Found 'world' in the string\n";
}
?>
Output:
Found 'world' in the string
Example 2: The following program demonstrates the mb_ereg_serach() function.
PHP
<?php
$targetString = "The quick brown fox jumps over the lazy dog.";
$pattern = "america";
mb_internal_encoding("UTF-8");
mb_ereg_search_init($targetString, $pattern);
if (mb_ereg_search()) {
echo "The pattern was found in the target string.\n";
}
else {
echo "The pattern was not found in the target string.\n";
}
?>
Output:
The pattern was not found in the target string.
Reference: https://www.php.net/manual/en/function.mb-ereg-search.php