{"id":86,"date":"2012-11-20T20:13:14","date_gmt":"2012-11-20T12:13:14","guid":{"rendered":"http:\/\/www.yeetrack.com\/post\/2012-11-20\/php%25E5%25AD%2597%25E7%25AC%25A6%25E4%25B8%25B2%25E5%25A4%2584%25E7%2590%2586%25E5%2587%25BD%25E6%2595%25B0"},"modified":"2013-04-20T17:26:30","modified_gmt":"2013-04-20T09:26:30","slug":"php%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%a4%84%e7%90%86%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=86","title":{"rendered":"php\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570"},"content":{"rendered":"<ol class=\"edui-filter-decimal\">\n<li>\n<p>trim()\u53bb\u9664\u5b57\u7b26\u4e32\u9996\u5c3e\u7684\u7a7a\u683c\u6216\u6307\u5b9a\u7684\u5b57\u7b26\u4e32,\u7c7b\u4f3cltrim()\u548crtrim()\u5206\u522b\u662f\u53bb\u9664\u5de6\uff0c\u53f3\u7684\u7a7a\u683c\u6216\u8005\u6307\u5b9a\u5b57\u7b26\u4e32<\/p>\n<\/li>\n<\/ol>\n<p><!--more--><\/p>\n<ol class=\"edui-filter-decimal\">\n<li>\n<p>\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">$str =&quot;hello  world  &quot;;\n    echo strlen($str) . &quot;&lt;br \/&gt;&quot;;\n    echo strlen(trim($str)) . &quot;&lt;br\/&gt;&quot;;\/\/\u53bb\u9664\u7a7a\u683c\n    echo trim($str,&quot;h d&quot;) . &quot;&lt;br \/&gt;&quot;;\/\/\u53bb\u9664\u7a7a\u683c\uff0c\u5b57\u7b26h\u548cd<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>str_pad()\u51fd\u6570\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u586b\u5145\uff0c\u9ed8\u8ba4\u5728\u53f3\u4fa7\u586b\u5145\u3002STR_PAD_BOTH(\u4e24\u4fa7\uff09\uff0cSTR_PAD_LEFT(\u5de6\u4fa7\uff09\uff0cSTR_PAD_RIGHT(\u53f3\u4fa7\uff09\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">$str2 = &quot;abc&quot;;\n    echo str_pad($str2,10,&quot;#&quot;) . &quot;&lt;br \/&gt;&quot;;\/\/\u9ed8\u8ba4\u5728\u53f3\u8fb9\u586b\u5145\n    echo str_pad($str2, 10, &quot;#&quot;, STR_PAD_LEFT) . &quot;&lt;br \/&gt;&quot;;\/\/\u7528#\u586b\u5145\u621010\u4e2a\u5b57\u7b26\uff0c\u5728\u5de6\u4fa7\u586b\u5145\n    $str3 =  strtoupper($str2) . &quot;&lt;br \/&gt;&quot;;\/\/strtolower()\u5168\u90e8\u8f6c\u6210\u5c0f\u5199\u5b57\u6bcd\n    echo $str3;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>ucfirst()\u5c06\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u7b26\u8f6c\u6210\u5927\u5199\uff0cucwords()\u5c06\u5b57\u7b26\u4e32\u7684\u6bcf\u4e2a\u5355\u8bcd\u9996\u5b57\u7b26\u8f6c\u6210\u5927\u5199\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo ucfirst($str) . &quot;&lt;br \/&gt;&quot;; \/\/ucfirst()\u5c06\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u6bcd\u8f6c\u6210\u5927\u5199\n    echo ucwords($str) . &quot;&lt;br \/&gt;&quot;;\/\/ucwords()\u5c06\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u4ee5\u7a7a\u683c\u5206\u5272\u7684\u5355\u8bcd\u9996\u5b57\u6bcd\u8f6c\u5927\u5199\n    $str4 = &quot; hi, Tom, welcome back!&quot;;\n    echo ucwords(strtolower($str4)) . &quot;&lt;br \/&gt;&quot;;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>nl2br()\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684n\u8f6c\u5316\u6210&lt;br \/&gt;\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo nl2br(&quot;Hello, world, nthis is my world!&quot;) . &quot;&lt;br \/&gt;&quot;;\/\/nl2br()\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684n\u89e3\u6790\u6210&lt;br \/&gt;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>htmlspecialchars()\u53ef\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684html\u6807\u8bb0\u8f6c\u6362\u6210\u666e\u901a\u5b57\u7b26\uff0c\u4f7f\u6d4f\u89c8\u5668\u4e0d\u4f1a\u89e3\u6790\u5b83\u4eec\u3002<br \/>\u5171\u4e09\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u662f\u8981\u5904\u7406\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u5f15\u53f7\u7684\u8f6c\u6362\u65b9\u6cd5\uff0c\u9ed8\u8ba4\u4e3aENT_COMPAT\uff0c\u53ea\u8f6c\u6362\u53cc\u5f15\u53f7\uff1bENT_QUOTES\u540c\u65f6\u8f6c\u6362\u4e24\u79cd\u5f15\u53f7\uff1bENT_NOQUOTES\u4e0d\u5bf9\u5f15\u53f7\u8fdb\u884c\u8f6c\u6362\u3002\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u5b9a\u7f16\u7801\u683c\u5f0f\uff0c\u9ed8\u8ba4\u4e3aiso88511-1<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo htmlspecialchars(&quot;&lt;html&gt;&lt;title&gt;this is title&lt;\/title&gt;&lt;body&gt;'Hello world!'&lt;\/body&gt;&lt;\/html&gt;&quot;, ENT_QUOTES) .&quot;&lt;br \/&gt;&quot;;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>htmlentites()\u4e0ehtmlspecialchars()\u51fd\u6570\u7c7b\u4f3c\uff0c\u5b83\u662f\u5c06\u6240\u6709\u7684\u975eascii\u5b57\u7b26\u8f6c\u6362\u6210\u5b9e\u4f53\u4ee3\u7801\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo htmlentities(&quot;\u4f60\u597d!'hello world'&lt;b&gt;bold&lt;\/b&gt;&quot;) . &quot;&lt;br \/&gt;&quot;;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>php.ini\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709magic_quote_gpc\uff0c\u5982\u679c\u5f00\u542f\uff0cphp\u518d\u5904\u7406\u8868\u5355\u65f6\uff0c\u4f1a\u9ed8\u8ba4\u5728\u5355\u5f15\u53f7\uff0c\u53cc\u5f15\u53f7\u548c\u53f3\u659c\u7ebf\u7b49\u7279\u6b8a\u5b57\u7b26\u8fdb\u884c\u8f6c\u4e49\u3002\u5982\u679c\u8be5\u914d\u7f6e\u9879\u6ca1\u6709\u6253\u5f00\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528stripslashes()\u51fd\u6570\u6765\u8fc7\u6ee4\u659c\u7ebf\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo stripslashes(&quot;hello world&quot;&quot;);<\/pre>\n<p>\u901a\u5e38stripslashes()\u51fd\u6570\u548chtmlspecialchars()\u51fd\u6570\u4e00\u8d77\u4f7f\u7528\uff0c\u6765\u8fc7\u6ee4\u7528\u6237\u7684\u975e\u6cd5\u8f93\u5165\u3002<\/p>\n<\/li>\n<li>\n<p>strip_tags()\u51fd\u6570\u7528\u6765\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u6307\u5b9a\u7684html\u6807\u7b7e\uff0c\u9ed8\u8ba4\u5220\u9664\u5168\u90e8\u6807\u7b7e\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e9b\u8fdb\u884c\u5220\u9664\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u8981\u4fdd\u7559\u7684html\u6807\u7b7e\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo strip_tags(&quot;&lt;title&gt;hello world&lt;\/title&gt;&lt;font color='red' size=15&gt;php \u5b66\u4e60&lt;\/font&gt;&quot;, &quot;&lt;font&gt;&quot;);<\/pre>\n<p>\u4e0a\u9762\u4e00\u884c\uff0c\u6307\u5b9a\u4fdd\u7559&lt;font&gt;\u6807\u7b7e\uff0c\u5220\u9664\u5168\u90e8\u5176\u4ed6\u7684\u6807\u7b7e\u3002<\/p>\n<\/li>\n<li>\n<p>strrev()\u51fd\u6570\u7528\u6765\u53cd\u8f6c\u5b57\u7b26\u4e32\uff0c\u5373\u5c06\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u5012\u5e8f\u8f93\u51fa\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo strrev(&quot;hello world&quot;) . &quot;&lt;br \/&gt;&quot;;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>md5()\u7528\u6765\u7528md5\u52a0\u5bc6\u7b97\u6cd5\u52a0\u5bc6\u6307\u5b9a\u5b57\u7b26\u4e32\uff0c\u9ed8\u8ba4\u662f32\u4f4d\u3002\u73b0\u5728\u540e\u53f0\u4fdd\u5b58\u5bc6\u7801\uff0c\u4e00\u822c\u662f\u53d6\u660e\u6587\u5bc6\u7801\u548c\u76d0\u503c\u7ec4\u5408\uff0c\u518d\u53bb\u7528md5\u6216\u5176\u4ed6\u7b97\u6cd5\u52a0\u5bc6\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo md5(&quot;password&quot;). &quot;&lt;br \/&gt;&quot;;<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>strcmp()\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u6309\u5b57\u8282\u987a\u5e8f\u8fdb\u884c\u6bd4\u8f83\uff0c\u5927\u5c0f\u5199\u654f\u611f\u3002str1=str2\uff0c\u8fd4\u56de0\uff1bstr1&gt;str2,\u8fd4\u56de1\uff1bstr1&lt;str2,\u8fd4\u56de-1.<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo strcmp(&quot;hello&quot;,&quot; Hello&quot;) . &quot;&lt;br \/&gt;&quot;;\/\/str1&gt;str2\uff0c\u8fd4\u56de1<\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n<li>\n<p>strcasecmp()\u51fd\u6570\u4e0estrcmp()\u51fd\u6570\u7c7b\u4f3c\uff0c\u4e0d\u8fc7strcasecmp()\u51fd\u6570\u5bf9\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u3002<\/p>\n<\/li>\n<li>\n<p>strnatcmp()\u51fd\u6570\u7528\u81ea\u7136\u65b9\u6cd5\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u6bd4\u8f83\u3002\u6240\u8c13\u201c\u81ea\u7136\u65b9\u6cd5\u201d\u5c31\u662f\u6309\u7167\u4eba\u7684\u601d\u7ef4\u65b9\u5f0f\u3002\u7531\u4e8ephp\u662f\u5f31\u7c7b\u578b\u8bed\u8a00\uff0c\u5982\u679c333\u548c44\u8fdb\u884c\u6bd4\u8f83\uff0c\u7528\u524d\u9762strcmp\u548cstrcasecmp\u8fdb\u884c\u6bd4\u8f83\uff0c333\u662f\u5c0f\u4e8e44\u7684\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">echo strnatcmp(&quot;333&quot;,&quot;44&quot;); \/\/\u6309\u7167\u81ea\u7136\u65b9\u6cd5\u8fdb\u884c\u6392\u5e8f\uff0c\u8fd4\u56de1<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>trim()\u53bb\u9664\u5b57\u7b26\u4e32\u9996\u5c3e\u7684\u7a7a\u683c\u6216\u6307\u5b9a\u7684\u5b57\u7b26\u4e32,\u7c7b\u4f3cltrim()\u548crtrim()\u5206\u522b\u662f\u53bb\u9664\u5de6\uff0c\u53f3\u7684\u7a7a\u683c\u6216\u8005\u6307\u5b9a\u5b57\u7b26\u4e32<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[24,7],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-coding","tag-php","tag-7"],"views":2583,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":396,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions\/396"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}