preg_last_error_msg()

preg_last_error_msg() — Returns the error message of the last PCRE regex execution.

Built-in function of PHP 8.5. The manual lists it as available in PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

preg_last_error_msg(): string

Parameters

This function takes no parameters.

Return value

Returns the error message on success, or "No error" if no error has occurred.

Example

A runnable snippet:

preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar'); if (preg_last_error() !== PREG_NO_ERROR) { echo preg_last_error_msg(); }

Output:

Backtrack limit exhausted

See also

preg_last_error()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page preg_last_error_msg() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.