Mbregex Functions are Deprecated in PHP 8.6

Mbregex Functions are Deprecated in PHP 8.6

In PHP, the mbstring extension provides its own set of regular expression functions, known as mbregex. They are built on the Oniguruma library and work independently of the PCRE functions such as preg_match.

Since PHP 8.6, the mbregex functions are deprecated, because maintenance of the Oniguruma library ended in April 2025:

<?php

$string = 'Grüße';

var_dump(mb_ereg('^\w+$', $string));
var_dump(mb_split('ü', $string));

Output:

Deprecated: Function mb_ereg() is deprecated since 8.6, because the underlying library is no longer maintained in main.php on line 5
bool(true)
Deprecated: Function mb_split() is deprecated since 8.6, because the underlying library is no longer maintained in main.php on line 6
array(2) {
  [0]=>
  string(2) "Gr"
  [1]=>
  string(3) "ße"
}

For most cases the PCRE functions with the u modifier are a suitable replacement:

<?php

$string = 'Grüße';

var_dump(preg_match('/^\w+$/u', $string));
var_dump(preg_split('/ü/u', $string));

Output:

int(1)
array(2) {
  [0]=>
  string(2) "Gr"
  [1]=>
  string(3) "ße"
}

The u modifier is required. Without it the pattern treats the subject as single bytes.

The return values are not always identical. The mb_ereg function returns a boolean, while preg_match returns an integer, so a comparison such as === true has to be adjusted. The mb_split and preg_split functions both return an array.

The following functions are deprecated:

Leave a Comment

Cancel reply

Your email address will not be published.