_wp_can_use_pcre_u()
Returns whether PCRE/u (PCRE_UTF8 modifier) is available for use.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null. Nothing (null).
Usage
_wp_can_use_pcre_u( $set );
- $set(true|false)
- Deprecated. This argument is no longer used for testing purposes.
Default:null
Changelog
| Since 4.2.2 | Introduced. |
| Since 6.9.0 | Deprecated the $set argument. |
_wp_can_use_pcre_u() wp can use pcre u code WP 7.0
function _wp_can_use_pcre_u( $set = null ) {
static $utf8_pcre = null;
if ( isset( $set ) ) {
_deprecated_argument( __FUNCTION__, '6.9.0' );
}
if ( isset( $utf8_pcre ) ) {
return $utf8_pcre;
}
$utf8_pcre = true;
set_error_handler(
function ( $errno, $errstr ) use ( &$utf8_pcre ) {
if ( str_starts_with( $errstr, 'preg_match():' ) ) {
$utf8_pcre = false;
return true;
}
return false;
},
E_WARNING
);
/*
* Attempt to compile a PCRE pattern with the PCRE_UTF8 flag. For
* systems lacking Unicode support this will trigger a warning
* during compilation, which the error handler will intercept.
*/
preg_match( '//u', '' );
restore_error_handler();
return $utf8_pcre;
}