String processing mechanism modification


1. Strings containing hexadecimal characters are no longer regarded as numbers

Strings containing hexadecimal characters are no longer regarded as numbers and will no longer be treated differently. For example, the following code:

var_dump("0x123" == "291");     // bool(false)     (previously true)
var_dump(is_numeric("0x123"));  // bool(false)     (previously true)
var_dump("0xe" + "0x1");        // int(0)          (previously 16)
var_dump(substr("foo", "0x1")); // string(3) "foo" (previously "oo")
// Notice: A non well formed numeric value encountered
can use the filter_var function to check whether a string contains hexadecimal characters or whether it can be converted into an integer
$str = "0xffff";
$int = filter_var($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX);
if (false === $int) {
    throw new Exception("Invalid integer!");
}
var_dump($int); // int(65535)

2. \u{If it contains illegal characters later, an error will be reported

Unicode code point escape syntax has been added to double quotes and heredocs syntax. "\u{" must be followed by utf-8 characters. If it is a non-utf-8 character, an error will be reported:

$str = "\u{xyz}"; // Fatal error: Invalid UTF-8 codepoint escape sequence
You can avoid this error by escaping the first \.
 $str = "\u{xyz}"; // Works fine

If there is no { after "\u", there will be no effect:

$str = "\u202e"; // Works fine

##PHP IntlChar()

PHP 7 supports internationalization (i18n) and localization (l10n) through the intl extension. This extension is just a basic wrapper for the ICU library and provides similar methods and features to the ICU library.

PHP 7 exposes the Unicode character features in ICU through the new IntlChar class. This class itself defines many static methods for operating unicode characters from multiple character sets.

Example

<?php
printf('%x', IntlChar::CODEPOINT_MAX);
echo IntlChar::charName('@');
var_dump(IntlChar::ispunct('!'));
?>

The execution output of the above program is:

10ffff
COMMERCIAL AT
bool(true)