Open In App

PHP mb_eregi() Function

Last Updated : 03 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mb_eregi() function is an inbuilt function in PHP that performs case-insensitive regular expression matches on a string having multibyte support. If the string pattern is matched, then it will return the string otherwise it will return false.

Syntax:

mb_eregi(
string $pattern,
string $string,
array &$matches = null
): 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: This is the string where we search our pattern.
  • $matches: This is the parameter that stores the matched substrings which starts from the left parentheses from the $string input. $matches[1] will have the matched substring which starts at the first left parentheses and $matches[2] will have the matched substring which starts at the second left parentheses and so on.

Return Values: The mb_eregi() function returns a boolean value after executing the case insensitive regular expression. If the function found the pattern in the given string, it will return “true”, otherwise it will return “false”.

Program 1: The following program demonstrates the mb_eregi() function.

PHP




<?php
  
$string = "Hello, World!";
$pattern = "world";
  
// Set the multibyte encoding
mb_regex_encoding("UTF-8");
  
if (mb_eregi($pattern, $string)) {
    echo "Pattern found!";
} else {
    echo "Pattern not found.";
}
  
?>


Output

Pattern found!

Program 2: The following program demonstrates the mb_eregi() function.

PHP




<?php
  
$subject = "VDwS0ErZ5K";
  
if (mb_eregi("^[A-Za-z\s]+$", $subject)) {
    echo "Match found!";
} else {
    echo "Match not found!";
}
  
?>


Output

Match not found!

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads