{"id":520,"date":"2025-06-11T00:13:06","date_gmt":"2025-06-10T16:13:06","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/szyzfc\/520.html"},"modified":"2025-06-11T00:13:06","modified_gmt":"2025-06-10T16:13:06","slug":"php%ef%bc%9a%e6%a3%80%e6%9f%a5%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%98%af%e5%90%a6%e4%b8%ba%e7%a9%ba%e7%9a%84%e4%ba%94%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/520.html","title":{"rendered":"PHP\uff1a\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\u7684\u4e94\u79cd\u65b9\u6cd5"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"&#23567;&#36213;&#30721;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#23567;&#36213;&#30721;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#24403;&#28982;&#21487;&#20197;&#65281;&#20197;&#19979;&#26159;&#19968;&#20123;&#24120;&#35265;&#30340;&#26041;&#27861;&#26469;&#26816;&#26597; PHP &#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#65306;<\/p>\n<h3>&#26041;&#27861;&#19968;&#65306;&#20351;&#29992; <code>empty()<\/code> &#20989;&#25968;<\/h3>\n<p><code>empty()<\/code> &#20989;&#25968;&#20250;&#36820;&#22238;&#19968;&#20010;&#24067;&#23572;&#20540;&#65292;&#34920;&#31034;&#21464;&#37327;&#26159;&#21542;&#20026;&#31354;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$string = '';\n\nif (empty($string)) {\n    echo \"&#23383;&#31526;&#20018;&#26159;&#31354;&#30340;\";\n} else {\n    echo \"&#23383;&#31526;&#20018;&#19981;&#26159;&#31354;&#30340;\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#20108;&#65306;&#20351;&#29992; <code>trim()<\/code> &#21644; <code>strlen()<\/code> &#20989;&#25968;<\/h3>\n<p>&#39318;&#20808;&#21435;&#38500;&#23383;&#31526;&#20018;&#20004;&#31471;&#30340;&#31354;&#30333;&#23383;&#31526;&#65292;&#28982;&#21518;&#26816;&#26597;&#38271;&#24230;&#26159;&#21542;&#20026; 0&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$string = '   ';\n\nif (trim($string) === '') {\n    echo \"&#23383;&#31526;&#20018;&#26159;&#31354;&#30340;\";\n} else {\n    echo \"&#23383;&#31526;&#20018;&#19981;&#26159;&#31354;&#30340;\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#19977;&#65306;&#20351;&#29992; <code>isset()<\/code> &#21644; <code>!empty()<\/code> &#20989;&#25968;<\/h3>\n<p>&#20808;&#26816;&#26597;&#21464;&#37327;&#26159;&#21542;&#23384;&#22312;&#65292;&#28982;&#21518;&#20877;&#26816;&#26597;&#20854;&#26159;&#21542;&#20026;&#31354;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$string = '';\n\nif (isset($string) &amp;&amp; !empty($string)) {\n    echo \"&#23383;&#31526;&#20018;&#19981;&#26159;&#31354;&#30340;\";\n} else {\n    echo \"&#23383;&#31526;&#20018;&#26159;&#31354;&#30340;\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#22235;&#65306;&#20351;&#29992; <code>is_null()<\/code> &#20989;&#25968;<\/h3>\n<p>&#22914;&#26524;&#21464;&#37327;&#26159; <code>null<\/code>&#65292;&#21017;&#35748;&#20026;&#23427;&#26159;&#31354;&#30340;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$string = null;\n\nif (is_null($string)) {\n    echo \"&#23383;&#31526;&#20018;&#26159;&#31354;&#30340;\";\n} else {\n    echo \"&#23383;&#31526;&#20018;&#19981;&#26159;&#31354;&#30340;\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#20116;&#65306;&#33258;&#23450;&#20041;&#20989;&#25968;<\/h3>\n<p>&#20320;&#21487;&#20197;&#32534;&#20889;&#19968;&#20010;&#33258;&#23450;&#20041;&#20989;&#25968;&#26469;&#26816;&#26597;&#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nfunction isEmptyString($str) {\n    return trim($str) === '';\n}\n\n$string = '';\n\nif (isEmptyString($string)) {\n    echo \"&#23383;&#31526;&#20018;&#26159;&#31354;&#30340;\";\n} else {\n    echo \"&#23383;&#31526;&#20018;&#19981;&#26159;&#31354;&#30340;\";\n}\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20123;&#26041;&#27861;&#21508;&#26377;&#20248;&#32570;&#28857;&#65292;&#36873;&#25321;&#21738;&#31181;&#26041;&#27861;&#21462;&#20915;&#20110;&#20320;&#30340;&#20855;&#20307;&#38656;&#27714;&#21644;&#20195;&#30721;&#39118;&#26684;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#23567;&#39532;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#23567;&#39532;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><p>&#22312;PHP&#20013;&#65292;&#20934;&#30830;&#26816;&#26597;&#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#23545;&#20110;&#36755;&#20837;&#39564;&#35777;&#12289;&#34920;&#21333;&#22788;&#29702;&#21644;&#25968;&#25454;&#22788;&#29702;&#33267;&#20851;&#37325;&#35201;&#12290;&#26412;&#25351;&#21335;&#23558;&#20171;&#32461;&#22810;&#31181;&#23454;&#29616;&#26041;&#27861;&#65292;&#27599;&#31181;&#26041;&#27861;&#37117;&#26377;&#20854;&#20248;&#21183;&#21644;&#36866;&#29992;&#22330;&#26223;&#12290;<\/p><h2>&#35299;&#20915;&#26041;&#26696; 1&#65306;&#20351;&#29992; empty()<\/h2><p>&#25551;&#36848;&#65306;empty() &#20989;&#25968;&#29992;&#20110;&#26816;&#26597;&#21464;&#37327;&#26159;&#21542;&#20026;&#31354;&#23383;&#31526;&#20018;&#12289;&#38646;&#12289;&#20551;&#20540;&#25110;&#26410;&#23450;&#20041;&#12290;<\/p><p>&#20998;&#26512;&#24067;&#23572;&#32467;&#26524;&#65306;&#22914;&#26524;&#23383;&#31526;&#20018;&#20026;&#31354;&#65292;&#21017;&#36820;&#22238;true&#12290;<\/p><p>&#20351;&#29992;&#24102;&#26377;&#31354;&#20540;&#26816;&#26597;&#30340;&#21464;&#37327;&#65288;&#21363;&#36890;&#36807; empty() &#26041;&#27861;&#65289;&#12290;<\/p><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>$string = '';\nif (empty($string)) {\n    echo 'The string is empty.';\n} else {\n    echo 'The string is not empty.';\n}\n<\/code><\/pre><p>&#25552;&#31034;&#65306;empty() &#20989;&#25968;&#20063;&#35748;&#20026; &#8216;0&#8217; &#20026;&#31354;&#65292;&#36825;&#21487;&#33021;&#19981;&#29702;&#24819;&#12290;<\/p><h2>&#35299;&#20915;&#26041;&#26696;2&#65306;&#19982;&#31354;&#23383;&#31526;&#20018;&#23383;&#38754;&#37327;&#36827;&#34892;&#27604;&#36739;<\/h2><p>&#25551;&#36848;&#65306;&#19982;&#31354;&#23383;&#31526;&#20018;&#23383;&#38754;&#37327;&#30340;&#30452;&#25509;&#27604;&#36739;&#21487;&#20197;&#36991;&#20813;&#22312;&#26816;&#26597;&#23383;&#31526;&#20018;&#26102;&#20986;&#29616;&#20551;&#38451;&#24615;&#12290;<\/p><p>&#20998;&#26512;&#24067;&#23572;&#32467;&#26524;&#12290;<\/p><p>&#27604;&#36739;&#23383;&#31526;&#20018;&#24212;&#30452;&#25509;&#19982; &#8220;.&#8221; &#36827;&#34892;&#27604;&#36739;&#12290;<\/p><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>$string = '';\nif ($string === '') {\n    echo 'The string is empty.';\n} else {\n    echo 'The string is not empty.';\n}\n<\/code><\/pre><p>&#27880;&#24847;&#20107;&#39033;&#65306;&#20351;&#29992;&#31561;&#21495;&#65288;===&#65289;&#20195;&#26367;&#36816;&#31639;&#31526;&#21487;&#20197;&#36991;&#20813;&#31867;&#22411;&#36716;&#25442;&#38382;&#39064;&#12290;<\/p><h2>&#35299;&#20915;&#26041;&#26696; 3&#65306;&#20351;&#29992; strlen()<\/h2><p>&#20989;&#25968;strlen()&#36820;&#22238;&#23383;&#31526;&#20018;&#30340;&#38271;&#24230;&#12290;&#22914;&#26524;&#38271;&#24230;&#20026;0&#65292;&#34920;&#31034;&#35813;&#23383;&#31526;&#20018;&#20026;&#31354;&#12290;<\/p><p>&#26816;&#26597;&#32467;&#26524;&#26159;&#21542;&#20026;0&#12290;<\/p><p>&#24212;&#29992;strlen()&#20989;&#25968;&#21040;&#23383;&#31526;&#20018;&#19978;&#12290;<\/p><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>$string = '';\nif (strlen($string) === 0) {\n    echo 'The string is empty.';\n} else {\n    echo 'The string is not empty.';\n}\n<\/code><\/pre><p>&#27880;&#24847;&#65306;strlen() &#26159;&#20108;&#36827;&#21046;&#23433;&#20840;&#21644;&#22810;&#23383;&#33410;&#23383;&#31526;&#23433;&#20840;&#30340;&#65292;&#36866;&#29992;&#20110;&#25152;&#26377;&#31867;&#22411;&#23383;&#31526;&#20018;&#65292;&#22240;&#27492;&#38750;&#24120;&#21487;&#38752;&#12290;<\/p><h2>&#35299;&#20915;&#26041;&#26696; 4&#65306;&#20351;&#29992; ctype_space()<\/h2><p>&#25551;&#36848;&#65306;ctype_space() &#20989;&#25968;&#26816;&#26597;&#23383;&#31526;&#20018;&#20013;&#30340;&#25152;&#26377;&#23383;&#31526;&#26159;&#21542;&#37117;&#26159;&#31354;&#30333;&#23383;&#31526;&#12290;&#23427;&#19981;&#20250;&#23558;&#31354;&#23383;&#31526;&#20018;&#35270;&#20026;&#31354;&#30333;&#23383;&#31526;&#12290;<\/p><p>&#32771;&#34385;&#31354;&#23383;&#31526;&#20018;&#20250;&#23548;&#33268;&#32467;&#26524;&#20026;&#20551;&#12290;<\/p><p>&#26816;&#26597;&#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#26684;&#25110;&#19982;&#31354;&#23383;&#31526;&#20018;&#30456;&#31561;&#12290;<\/p><p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>$string = '';\nif (ctype_space($string) || $string === '') {\n    echo 'The string is empty or only whitespace.';\n} else {\n    echo 'The string is not empty.';\n}\n<\/code><\/pre><p>&#27880;&#24847;&#65306;ctype_space() &#19981;&#20250;&#23558;&#31354;&#23383;&#31526;&#20018;&#35270;&#20026;&#31354;&#30333;&#23383;&#31526;&#65292;&#32780;&#21482;&#20250;&#35782;&#21035;&#30001;&#32431;&#31354;&#30333;&#32452;&#25104;&#30340;&#23383;&#31526;&#20018;&#12290;<\/p><h2>&#35299;&#20915;&#26041;&#26696; 5&#65306;&#20351;&#29992; trim() &#21644;&#26816;&#26597;&#38271;&#24230;<\/h2><p>&#25551;&#36848;&#65306;trim() &#26041;&#27861;&#20250;&#21435;&#38500;&#23383;&#31526;&#20018;&#30340;&#24320;&#22836;&#21644;&#32467;&#23614;&#30340;&#31354;&#30333;&#23383;&#31526;&#65292;&#28982;&#21518;&#20320;&#21487;&#20197;&#26816;&#26597;&#20854;&#38271;&#24230;&#12290;<\/p><p>&#20351;&#29992; strlen() &#25110; empty() &#26816;&#26597;&#26159;&#21542;&#24050;&#21024;&#38500;&#23383;&#31526;&#20018;&#30340;&#21069;&#23548;&#21644;&#23614;&#38543;&#31354;&#26684;&#65292;&#20174;&#32780;&#30830;&#23450;&#35813;&#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#12290;<\/p><p>&#23545;&#23383;&#31526;&#20018;&#24212;&#29992;trim()&#26041;&#27861;&#12290;<\/p><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>$string = \"  tn\";\nif (empty(trim($string))) {\n    echo 'The string is empty.';\n} else {\n    echo 'The string is not empty.';\n}\n<\/code><\/pre><p>&#25552;&#31034;&#65306;trim() &#26041;&#27861;&#21482;&#20250;&#20174;&#23383;&#31526;&#20018;&#30340;&#24320;&#22987;&#21644;&#32467;&#23614;&#31227;&#38500;&#31354;&#30333;&#23383;&#31526;&#65292;&#32780;&#19981;&#20250;&#22312;&#20013;&#38388;&#36827;&#34892;&#25805;&#20316;&#12290;<\/p><h2>&#32467;&#35770;&#12290;<\/h2><p>&#20102;&#35299;&#22312;PHP&#20013;&#26816;&#26597;&#23383;&#31526;&#20018;&#26159;&#21542;&#20026;&#31354;&#30340;&#21508;&#31181;&#26041;&#27861;&#65292;&#20351;&#24320;&#21457;&#20154;&#21592;&#33021;&#22815;&#29702;&#35299;&#24182;&#36873;&#25321;&#26368;&#36866;&#21512;&#20854;&#19978;&#19979;&#25991;&#30340;&#26368;&#36866;&#24403;&#25216;&#26415;&#12290;&#20174;&#31616;&#21333;&#30340;empty()&#35843;&#29992;&#21040;&#26356;&#39640;&#32423;&#30340;ctype_space()&#26816;&#26597;&#65292;&#29702;&#35299;&#27599;&#20010;&#26041;&#27861;&#30340;&#34892;&#20026;&#12289;&#24615;&#33021;&#24433;&#21709;&#21644;&#38519;&#38449;&#65292;&#30830;&#20445;&#26500;&#24314;&#20986;&#31283;&#20581;&#19988;&#26080;&#38169;&#35823;&#30340;&#24212;&#29992;&#31243;&#24207;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&#23567;&#36213;&#30721;&#29422; &#24403;&#28982;&#21487;&#20197;&#65281;&#20197;&#19979;&#26159;&#19968;&#20123;&#24120;&#35265;&#30340;&#26041;&#27861;&#038;#26469..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[40],"tuisongtax":[],"class_list":["post-520","my1js","type-my1js","status-publish","hentry","my1js2nav-szyzfc"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=520"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=520"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=520"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}