PHP 7: Unicode escape syntax doesn't work on single quotes

蹲街弑〆低调 提交于 2019-12-13 09:13:01

问题


Whenever strings are set with single quotes the unicode doesn't get decoded but the unicode does get decoded when set with double quotes.

How do I get the strings set by single quotes also to be decoded?

PHP

$poo = '\u{1F6BB}';
echo $poo;
$poo = "\u{1F6BB}";
echo $poo;

OUTPUT

\u{1F6BB}🚻

Example

http://sandbox.onlinephpfunctions.com/code/9a38e972226a6271996f512363c19332dae0b760


回答1:


The point of single-quoted strings is that they don't support escape characters.

The documentation says this very clearly:

All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n, will be output literally as specified rather than having any special meaning.



来源:https://stackoverflow.com/questions/45088086/php-7-unicode-escape-syntax-doesnt-work-on-single-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!