3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * preg_match() and //u pattern modifier * * @link https://stackoverflow.com/a/6723593/367456 */ $constants = function_exists('get_defined_constants') ? @get_defined_constants(true) : null; $pcreConstants = (array)@$constants['pcre']; $pcreConstants = null; if (empty($pcreConstants)) { $pcreConstants = array(); foreach (get_defined_constants() as $constant => $value) { if (6 === sscanf($constant, '%*[P]%*1[CR]%*1[RE]%*1[EG]%*[_]%n', $n)) { $pcreConstants[$constant] = $value; } } } $kMap = array_flip(array_keys($pcreConstants)); $ofVer = @$kMap['PCRE_VERSION']; $stop = $ofVer ? $ofVer : count($pcreConstants); $ofFirst = intval(@$kMap['PREG_NO_ERROR']); $errors = array_flip(array_slice($pcreConstants, $ofFirst, - $ofFirst + $stop)); $return = preg_match('//u', "\x80"); $matchesUTF8 = 1 === $return; $isMatchError = false === $return; $pregLastError = function_exists('preg_last_error') ? preg_last_error() : null; $pregLastErrorMsg = function_exists('preg_last_error_msg') ? preg_last_error_msg() : null; printf("\$return: %s\n", var_export($return, true)); printf("\$matchesUTF8: %s\n", var_export($matchesUTF8, true)); printf("\$isMatchError: %s\n", var_export($isMatchError, true)); printf("\$pregLastError: %s\n", var_export($pregLastError, true)); printf("\$pregLastErrorMsg: %s\n", var_export($pregLastErrorMsg, true)); printf("PREG_*_ERROR: %s\n", var_export(@$errors[$pregLastError], true)); printf("PCRE_VERSION: %s\n", @$pcreConstants['PCRE_VERSION']); $extPcreVer = function_exists('phpversion') ? @phpversion('pcre') : null; if ($extPcreVer === PHP_VERSION) $extPcreVer = 'PHP_VERSION'; printf("ext-pcre version: %s\n", var_export($extPcreVer, true)); echo 'pcre constants: ', print_r($pcreConstants, true);

preferences:
26.4 ms | 417 KiB | 5 Q