Open In App

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.

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
  
$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
  
$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


Article Tags :