The mb_ereg() function is an inbuilt function in PHP that is used for searching a string in the multibyte string by using the regular expression.
Syntax:
mb_ereg($pattern, $string, $matches ): bool
Parameters: The following function has three parameters that are described below.
- $pattern: The regular expression pattern that we used for matching against the multibyte string.
- $string: The string to search for a match.
- $matches: This is the optional parameter that stored the match elements in the array.
Return Values: The mb_ereg() function returns either “true” or “false” depending on whether the regular expression pattern matches the string. If the optional $matches parameter is provided, any matched subpatterns will be stored in the array.
Example 1: The following code demonstrates the mb_ereg() function.
PHP
<?php $subject = "12345This is String" ; if (mb_ereg( "^[A-Za-z\s]+$" , $subject )) { echo "Match found!" ; } else { echo "Match not found!" ; } ?> |
Output:
Match not found!
Example 2: The following code demonstrates the mb_ereg() function.
PHP
<?php mb_regex_encoding( 'UTF-8' ); $pattern = '[0-9]+[a-zA-Z]+' ; $string = '123abc' ; if (mb_ereg( $pattern , $string )) { echo 'Pattern matched successfully!' ; } else { echo 'Pattern did not match.' ; } ?> |
Output:
Pattern matched successfully!
Reference: https://www.php.net/manual/en/function.mb-ereg.php