{"id":265,"date":"2024-09-06T10:36:54","date_gmt":"2024-09-06T02:36:54","guid":{"rendered":"http:\/\/znl.pub\/?p=265"},"modified":"2024-09-06T10:36:54","modified_gmt":"2024-09-06T02:36:54","slug":"php%e5%8f%98%e9%87%8f%e5%be%aa%e7%8e%af%ef%bc%88%e9%81%8d%e5%8e%86%ef%bc%89%e6%89%93%e5%8d%b0unicode%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/znl.pub\/?p=265","title":{"rendered":"PHP\u53d8\u91cf\u5faa\u73af\uff08\u904d\u5386\uff09\u6253\u5370unicode\u5b57\u7b26"},"content":{"rendered":"\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5f97\u5148\u63d0\u4e00\u4e2aPHP\u8bed\u6cd5\uff1a\\u{}\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;znl.pub ~ ]# php -r 'echo \"\\u{2440}\".PHP_EOL;'\n\u2440<\/code><\/pre>\n\n\n\n<p> \u6ce8\u610f\u662f\u6211\u4eec\u662f\u7528\u7684\u53cc\u5f15\u53f7\uff0c\u5982\u679c\u4f60\u7528\u5355\u5f15\u53f7\uff0c\u5c31\u4e0d\u4f1a\u8f6c\u4e49\u800c\u662f\u76f4\u63a5\u8f93\u51fa \\u{2440}\uff1b\u8fd8\u6709\u8981\u6ce8\u610f\u5c31\u662f\u82b1\u62ec\u53f7\u91cc\u7684\u6570\u662f16\u8fdb\u5236\u6570\u3002\u63a5\u4e0b\u6765\u6211\u5c31\u60f3\uff1a\u80fd\u4e0d\u80fd\u8bbe\u7f6e\u4e00\u4e2a16\u8fdb\u5236\u6570\u7684\u53d8\u91cf\uff0c\u8ba9\u4ed6\u81ea\u589e\u52a01\uff0c\u7136\u540e\u5faa\u73af\u6253\u5370\u5bf9\u5e94\u7684unicode\u5b57\u7b26\u5462\uff1f\u90a3\u6211\u4eec\u5148\u6765\u6d4b\u8bd5\u4e00\u4e0b\u53d8\u91cf\u80fd\u4e0d\u80fd\u7ec4\u5408\u540e\u89e3\u6790\u5427\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;znl.pub ~]# php -a \nphp > \/\/ \u5b9a\u4e49\u521d\u59cb\u5341\u516d\u8fdb\u5236\u6570\nphp > $a = \"2440\";\n\nphp > \/\/ \u4f7f\u7528 \\u{} \u8bed\u6cd5\u8f93\u51fa Unicode \u5b57\u7b26\nphp > echo \"\\u{$a}\".PHP_EOL;\nPHP Warning:  Undefined variable $a in php shell code on line 1\n\nphp > echo \"\\u{{$a}}\".PHP_EOL;\nPHP Parse error:  Invalid UTF-8 codepoint escape sequence in php shell code on line 1\n\nphp > echo \"\\u{\" . $a . \"}\" . PHP_EOL;\nPHP Parse error:  Invalid UTF-8 codepoint escape sequence in php shell code on line 1\n\nphp > \/\/ \u5148\u8bbe\u7f6e\u6210\u4e00\u4e2a\u53d8\u91cf\u518d\u8bd5\u8bd5\uff1f\nphp > $b=\"\\u{\".$a.\"}\";\nPHP Parse error:  Invalid UTF-8 codepoint escape sequence in php shell code on line 1\n\nphp > $b=\"\\u{\".$a;\nPHP Parse error:  Invalid UTF-8 codepoint escape sequence in php shell code on line 1\n\nphp > $b=\"\\u\".\"{\".$a.\"}\"; \/\/\u8fd9\u6b21\u6ca1\u62a5\u9519\uff0c\u6293\u7d27echo \u8bd5\u8bd5\nphp > echo $b;\n\\u{2440}  \/\/ \u663e\u7136\u53c8\u5931\u8d25\u4e86\n<\/code><\/pre>\n\n\n\n<p>\u54ce\uff0c\u96be\u9053\u5c31\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\u4e86\u5417\uff1f\u5176\u5b9e\u4e0d\u7136\uff0cphp\u8fd8\u6709\u4e2a\u6740\u624b\u950f\u51fd\u6570json_decode()\uff0c\u54c8\u54c8\uff0c\u6bd5\u7adf\u4ed6\u80fd\u5c06 \\uXXXX \u8fd9\u79cd\u5199\u6cd5\u7684unicode\u89e3\u7801\u554a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u7d27\u63a5\u4e0a\u6bb5\nphp > echo json_decode('\"\\u2440\"');\n\u2440\nphp > echo json_decode('\"\\u'.$a.'\"'); \n\u2440  \/\/ \u6210\u4e86<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u7ed9\u51fa\u5b8c\u6574\u904d\u5386\u53ef\u7528\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n\/\/ \u5b9a\u4e49\u521d\u59cb\u5341\u516d\u8fdb\u5236\u6570\n$a = \"2440\";\n\n\/\/ \u5faa\u73af\u6b21\u6570\n$maxIterations = 10000;\n\n\/\/ \u5faa\u73af\u52a01\u5e76\u6253\u5370\u7ed3\u679c\nfor ($i = 1; $i &lt; $maxIterations; $i++) {\n    \/\/ \u5c06\u5341\u516d\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\n    $b = hexdec($a);\n\n    \/\/ \u52a01\n    $b++;\n\n    \/\/ \u5c06\u65b0\u7684\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u56de\u5341\u516d\u8fdb\u5236\u6570\n    $a = dechex($b);\n\n    \/\/ \u8f93\u51fa Unicode \u5b57\u7b26\n    echo json_decode('\"\\u' . sprintf('%04s', $a) . '\"') . PHP_EOL;\n}\n\n?><\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<h3 class=\"wp-block-heading\">\u8bf4\u660e\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>sprintf('%04s', $a)<\/code><\/strong>: \u786e\u4fdd\u5341\u516d\u8fdb\u5236\u6570\u5b57\u59cb\u7ec8\u662f\u56db\u4f4d\uff0c\u4e0d\u8db3\u7684\u7528\u96f6\u586b\u5145\u3002<\/li>\n\n\n\n<li><strong><code>json_decode<\/code><\/strong>: \u89e3\u6790 Unicode \u5b57\u7b26\u4e32\uff0c\u786e\u4fdd\u6b63\u786e\u8f93\u51fa\u3002<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u6211\u4eec\u5f97\u5148\u63d0\u4e00\u4e2aPHP\u8bed\u6cd5\uff1a\\u{}\u3002\u6bd4\u5982\uff1a \u6ce8\u610f\u662f\u6211\u4eec\u662f\u7528\u7684\u53cc\u5f15\u53f7\uff0c\u5982\u679c\u4f60\u7528\u5355\u5f15\u53f7\uff0c\u5c31\u4e0d\u4f1a\u8f6c\u4e49\u800c\u662f\u76f4\u63a5\u8f93&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,22],"tags":[],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-php","category-22"],"_links":{"self":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265"}],"version-history":[{"count":1,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}