{"id":2576,"date":"2017-08-06T19:49:40","date_gmt":"2017-08-06T11:49:40","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=2576"},"modified":"2017-08-06T19:49:40","modified_gmt":"2017-08-06T11:49:40","slug":"php%e9%87%8c10%e4%b8%aa%e9%b2%9c%e4%b8%ba%e4%ba%ba%e7%9f%a5%e4%bd%86%e5%8d%b4%e9%9d%9e%e5%b8%b8%e6%9c%89%e7%94%a8%e7%9a%84%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php%e9%87%8c10%e4%b8%aa%e9%b2%9c%e4%b8%ba%e4%ba%ba%e7%9f%a5%e4%bd%86%e5%8d%b4%e9%9d%9e%e5%b8%b8%e6%9c%89%e7%94%a8%e7%9a%84%e5%87%bd%e6%95%b0\/","title":{"rendered":"PHP\u91cc10\u4e2a\u9c9c\u4e3a\u4eba\u77e5\u4f46\u5374\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570"},"content":{"rendered":"<p>PHP\u91cc\u6709\u975e\u5e38\u4e30\u5bcc\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u5f88\u591a\u6211\u4eec\u90fd\u7528\u8fc7\uff0c\u4f46\u4ecd\u6709\u5f88\u591a\u7684\u51fd\u6570\u6211\u4eec\u5927\u90e8\u5206\u4eba\u90fd\u4e0d\u719f\u6089\uff0c\u53ef\u5b83\u4eec\u5374\u5341\u5206\u7684\u6709\u7528\u3002\u8fd9\u7bc7\u6587\u7ae0\u91cc\uff0c\u6211\u5217\u4e3e\u4e86\u4e00\u4e9b\u9c9c\u4e3a\u4eba\u77e5\u4f46\u4f1a\u8ba9\u4f60\u773c\u775b\u4e00\u4eae\u7684PHP\u51fd\u6570\u3002<\/p>\n<p>levenshtein()<\/p>\n<p>\u4f60\u6709\u6ca1\u6709\u7ecf\u5386\u8fc7\u9700\u8981\u77e5\u9053\u4e24\u4e2a\u5355\u8bcd\u6709\u591a\u5927\u7684\u4e0d\u540c\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u6765\u5e2e\u4f60\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u3002\u5b83\u80fd\u6bd4\u8f83\u51fa\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u7a0b\u5ea6\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>$str1 = &#8220;carrot&#8221;;<\/p>\n<p>$str2 = &#8220;carrrott&#8221;;<\/p>\n<p>echo levenshtein($str1, $str2); \/\/Outputs 2<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/php.net\/manual\/en\/function.levenshtein.php<\/p><\/blockquote>\n<p>get_defined_vars()<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5728debug\u8c03\u8bd5\u65f6\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6240\u6709\u5b9a\u4e49\u8fc7\u7684\u53d8\u91cf\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>print_r(get_defined_vars());<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/php.net\/manual\/en\/function.get-defined-vars.php<\/p><\/blockquote>\n<p>php_check_syntax()<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u975e\u5e38\u7684\u6709\u7528\uff0c\u53ef\u4ee5\u7528\u6765\u68c0\u67e5PHP\u7684\u8bed\u6cd5\u662f\u5426\u6b63\u786e\u3002\u51fa\u4e8e\u6280\u672f\u4e0a\u7684\u539f\u56e0\uff0c\u4ecePHP 5.05\u5f00\u59cb\uff0c\u8fd9\u4e2a\u51fd\u6570\u88ab\u5220\u9664\u4e86\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>$error_message = &#8220;&#8221;;<\/p>\n<p>$filename = &#8220;.\/php_script.php&#8221;;<\/p>\n<p>if(!php_check_syntax($filename, &amp;$error_message)) {<\/p>\n<p>echo &#8220;Errors were found in the file $filename: $error_message&#8221;;<\/p>\n<p>} else {<\/p>\n<p>echo &#8220;The file $filename contained no syntax errors&#8221;;<\/p>\n<p>}<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/www.php.net\/manual\/en\/function.php-check-syntax.php<\/p><\/blockquote>\n<p>ignore_user_abort()<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u7528\u6765\u62d2\u7edd\u6d4f\u89c8\u5668\u7aef\u7528\u6237\u7ec8\u6b62\u6267\u884c\u811a\u672c\u7684\u8bf7\u6c42\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\u5ba2\u6237\u7aef\u7684\u9000\u51fa\u4f1a\u5bfc\u81f4\u670d\u52a1\u5668\u7aef\u811a\u672c\u505c\u6b62\u8fd0\u884c\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>ignore_user_abort();<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/www.php.net\/manual\/en\/function.ignore-user-abort.php<\/p><\/blockquote>\n<p>highlight_string()<\/p>\n<p>\u5f53\u4f60\u60f3\u628aPHP\u4ee3\u7801\u663e\u793a\u5230\u9875\u9762\u4e0a\u65f6\uff0chighlight_string()\u51fd\u6570\u5c31\u4f1a\u663e\u5f97\u975e\u5e38\u6709\u7528\u3002\u8fd9\u4e2a\u51fd\u6570\u4f1a\u628a\u4f60\u63d0\u4f9b\u7684PHP\u4ee3\u7801\u7528\u5185\u7f6e\u7684PHP\u8bed\u6cd5\u7a81\u51fa\u663e\u793a\u5b9a\u4e49\u7684\u989c\u8272\u9ad8\u4eae\u663e\u793a\u3002\u8fd9\u4e2a\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u9700\u8981\u88ab\u7a81\u51fa\u663e\u793a\u3002\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5982\u679c\u8bbe\u7f6e\u6210TRUE\uff0c\u8fd9\u4e2a\u51fd\u6570\u5c31\u4f1a\u628a\u9ad8\u4eae\u540e\u7684\u4ee3\u7801\u5f53\u6210\u8fd4\u56de\u503c\u8fd4\u56de\u3002<\/p>\n<p>\u7528\u6cd5<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>highlight_string(&#8216; &lt;?php phpinfo(); ?&gt;&#8217;);<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/php.net\/manual\/en\/function.highlight-string.php<\/p><\/blockquote>\n<p>highlight_file<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684PHP\u51fd\u6570\uff0c\u5b83\u80fd\u8fd4\u56de\u6307\u5b9a\u7684PHP\u6587\u4ef6\uff0c\u5e76\u6309\u7167\u8bed\u6cd5\u8bed\u4e49\u7528\u9ad8\u4eae\u989c\u8272\u7a81\u51fa\u663e\u793a\u6587\u4ef6\u5185\u5bb9\u3002\u5176\u4e2d\u7684\u7a81\u51fa\u663e\u793a\u7684\u4ee3\u7801\u90fd\u662f\u7528HTML\u6807\u8bb0\u5904\u7406\u8fc7\u7684\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>highlight_file(&#8220;php_script.php&#8221;);<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/www.php.net\/manual\/en\/function.highlight-file.php<\/p><\/blockquote>\n<p>php_strip_whitespace<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u4e5f\u8ddf\u524d\u9762\u7684show_source()\u51fd\u6570\u76f8\u4f3c\uff0c\u4f46\u5b83\u4f1a\u5220\u9664\u6587\u4ef6\u91cc\u7684\u6ce8\u91ca\u548c\u7a7a\u683c\u7b26\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>echo php_strip_whitespace(&#8220;php_script.php&#8221;);<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/www.php.net\/manual\/en\/function.php-strip-whitespace.php<\/p><\/blockquote>\n<p>get_browser<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u4f1a\u8bfb\u53d6browscap.ini\u6587\u4ef6\uff0c\u8fd4\u56de\u6d4f\u89c8\u5668\u517c\u5bb9\u4fe1\u606f\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>echo $_SERVER[&#8216;HTTP_USER_AGENT&#8217;];<\/p>\n<p>$browser = get_browser();<\/p>\n<p>print_r($browser);<\/p>\n<p>?&gt;<\/p>\n<p>Source: https:\/\/www.php.net\/manual\/en\/function.get-browser.php<\/p><\/blockquote>\n<p>memory_get_usage(),memory_get_peak_usage(),getrusage()<\/p>\n<p>\u8fd9\u4e9b\u51fd\u6570\u7528\u6765\u83b7\u53d6\u5185\u5b58\u548cCPU\u4f7f\u7528\u60c5\u51b5\uff0cmemory_get_usage()\u51fd\u6570\u8fd4\u56de\u5185\u5b58\u4f7f\u7528\u91cf\uff0cmemory_get_peak_usage()\u51fd\u6570\u8fd4\u56de\u5185\u5b58\u4f7f\u7528\u5cf0\u503c\uff0cgetrusage()\u8fd4\u56deCUP\u4f7f\u7528\u60c5\u51b5\uff0c\u5728\u8c03\u8bd5PHP\u4ee3\u7801\u6027\u80fd\u65f6\uff0c\u8fd9\u4e9b\u51fd\u6570\u4f1a\u7ed9\u4f60\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u4fe1\u606f\u3002\u4f46\u6709\u4e00\u70b9\u8bf7\u6ce8\u610f\uff0c\u5728\u8fd9\u4e9b\u51fd\u6570\u4e2dWindow\u4e0a\u65e0\u6548\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>echo &#8220;Initial: &#8220;.memory_get_usage().&#8221; bytes \\n&#8221;;<\/p>\n<p>echo &#8220;Peak: &#8220;.memory_get_peak_usage().&#8221; bytes \\n&#8221;;<\/p>\n<p>$data = getrusage();<\/p>\n<p>echo &#8220;User time: &#8220;.<\/p>\n<p>($data[&#8216;ru_utime.tv_sec&#8217;] +<\/p>\n<p>$data[&#8216;ru_utime.tv_usec&#8217;] \/ 1000000);<\/p>\n<p>echo &#8220;System time: &#8220;.<\/p>\n<p>($data[&#8216;ru_stime.tv_sec&#8217;] +<\/p>\n<p>$data[&#8216;ru_stime.tv_usec&#8217;] \/ 1000000);<\/p>\n<p>?&gt;<\/p><\/blockquote>\n<p>gzcompress(), gzuncompress()<\/p>\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u7528\u6765\u538b\u7f29\u548c\u89e3\u538b\u5b57\u7b26\u4e32\u6570\u636e\u3002\u5b83\u4eec\u7684\u538b\u7f29\u7387\u80fd\u8fbe\u523050% \u5de6\u53f3\u3002\u53e6\u5916\u7684\u51fd\u6570 gzencode() \u548c gzdecode() \u4e5f\u80fd\u8fbe\u5230\u7c7b\u4f3c\u7ed3\u679c\uff0c\u4f46\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u538b\u7f29\u7b97\u6cd5\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p>$string =<\/p>\n<p>&#8220;Lorem ipsum dolor sit amet, consectetur<\/p>\n<p>adipiscing elit. Nunc ut elit id mi ultricies<\/p>\n<p>adipiscing. Nulla facilisi. Praesent pulvinar,<\/p>\n<p>sapien vel feugiat vestibulum, nulla dui pretium orci,<\/p>\n<p>non ultricies elit lacus quis ante. Lorem ipsum dolor<\/p>\n<p>sit amet, consectetur adipiscing elit. Aliquam<\/p>\n<p>pretium ullamcorper urna quis iaculis. Etiam ac massa<\/p>\n<p>sed turpis tempor luctus. Curabitur sed nibh eu elit<\/p>\n<p>mollis congue. Praesent ipsum diam, consectetur vitae<\/p>\n<p>ornare a, aliquam a nunc. In id magna pellentesque<\/p>\n<p>tellus posuere adipiscing. Sed non mi metus, at lacinia<\/p>\n<p>augue. Sed magna nisi, ornare in mollis in, mollis<\/p>\n<p>sed nunc. Etiam at justo in leo congue mollis.<\/p>\n<p>Nullam in neque eget metus hendrerit scelerisque<\/p>\n<p>eu non enim. Ut malesuada lacus eu nulla bibendum<\/p>\n<p>id euismod urna sodales. &#8220;;<\/p>\n<p>$compressed = gzcompress($string);<\/p>\n<p>$original = gzuncompress($compressed);<\/p>\n<p>?&gt;<\/p><\/blockquote>\n<p>\u4f60\u662f\u5426\u4e5f\u60f3\u5230\u4e86\u8fd8\u6709\u5176\u5b83\u5f88\u6709\u7528\u7684\u51fd\u6570\uff1f\u8bf7\u5728\u8bc4\u8bba\u91cc\u5206\u4eab\u51fa\u6765\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u91cc\u6709\u975e\u5e38\u4e30\u5bcc\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u5f88\u591a\u6211\u4eec\u90fd\u7528\u8fc7\uff0c\u4f46\u4ecd\u6709\u5f88\u591a\u7684\u51fd\u6570\u6211\u4eec\u5927\u90e8\u5206\u4eba\u90fd\u4e0d\u719f\u6089\uff0c\u53ef\u5b83\u4eec\u5374\u5341\u5206\u7684\u6709\u7528\u3002\u8fd9\u7bc7\u6587 &#8230; <a title=\"PHP\u91cc10\u4e2a\u9c9c\u4e3a\u4eba\u77e5\u4f46\u5374\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php%e9%87%8c10%e4%b8%aa%e9%b2%9c%e4%b8%ba%e4%ba%ba%e7%9f%a5%e4%bd%86%e5%8d%b4%e9%9d%9e%e5%b8%b8%e6%9c%89%e7%94%a8%e7%9a%84%e5%87%bd%e6%95%b0\/\" aria-label=\"\u9605\u8bfb PHP\u91cc10\u4e2a\u9c9c\u4e3a\u4eba\u77e5\u4f46\u5374\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[753],"class_list":["post-2576","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=2576"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2576\/revisions"}],"predecessor-version":[{"id":2577,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2576\/revisions\/2577"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=2576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=2576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=2576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}