Thursday, May 21, 2026
HomeLanguagesPHP mb_eregi() Function

PHP mb_eregi() Function

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

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS