{"id":406,"date":"2014-12-24T15:12:57","date_gmt":"2014-12-24T07:12:57","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=406"},"modified":"2015-02-15T20:46:33","modified_gmt":"2015-02-15T12:46:33","slug":"php%e8%8e%b7%e5%8f%96%e8%a7%a3%e6%9e%90url%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=406","title":{"rendered":"PHP\u83b7\u53d6\u89e3\u6790URL\u65b9\u6cd5"},"content":{"rendered":"<p>\u901a\u8fc7url\u8fdb\u884c\u4f20\u503c\uff0c\u662fphp\u4e2d\u4e00\u4e2a\u4f20\u503c\u7684\u91cd\u8981\u624b\u6bb5\u3002\u6240\u4ee5\u6211\u4eec\u8981\u7ecf\u5e38\u5bf9url\u91cc\u9762\u6240\u5e26\u7684\u53c2\u6570\u8fdb\u884c\u89e3\u6790\uff0c\u5982\u679c\u6211\u4eec\u77e5\u9053\u4e86url\u4f20\u9012\u53c2\u6570\u540d\u79f0\uff0c\u4f8b\u5982:<\/p>\n<p><strong>\u3000\u3000\/index.php?name=tank&amp;sex=1#top<\/strong><\/p>\n<p>\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7$_GET[&#8216;name&#8217;]\uff0c$_GET[&#8216;sex&#8217;]\u6765\u83b7\u5f97\u4f20\u7684\u6570\u636e\u3002\u4f46\u662f\u5982\u679c\u6211\u4eec\u4e0d\u77e5\u9053\u8fd9\u4e9b\u53d8\u91cf\u540d\u53c8\u600e\u4e48\u529e\u5462\uff1f\u8fd9\u4e5f\u662f\u5199\u8fd9\u7bc7\u535a\u6587\u7684\u76ee\u7684\uff0c\u56e0\u4e3a\u81ea\u5df1\u8001\u662f\u5fd8\uff0c\u6240\u4ee5\u505a\u4e2a\u6807\u8bb0\uff0c\u4e0b\u6b21\u5c31\u4e0d\u8981\u5230\u5904\u627e\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901aphp\u7684\u53d8\u91cf\u6765\u83b7\u5f97url\u548c\u8981\u4f20\u7684\u53c2\u6570\u5b57\u7b26\u4e32\uff1a<\/p>\n<p><strong>\u3000\u3000$_SERVER[&#8220;QUERY_STRING&#8221;] name=tank&amp;sex=1<\/strong><\/p>\n<p><strong>\u3000\u3000$_SERVER[&#8220;REQUEST_URI&#8221;] \/index.php?name=tank&amp;sex=1<\/strong><\/p>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u4e0d\u80fd\u83b7\u53d6\u951a\u70b9\u7684\u503c\uff0c\u6bd4\u5982index.php?p=12#foot,\u8fd9\u91cc\u7684#foot\u662f\u4e0d\u80fd\u83b7\u53d6\u7684\uff0c\u6240\u4ee5\u5728\u4f20\u9012\u951a\u70b9\u7684\u503c\u7684\u65f6\u5019\u9700\u8981\u4f7f\u7528JS\u7684window.location.hash\u548cwindow.location.href\u3002<\/p>\n<p>javascript\u4e5f\u53ef\u4ee5\u83b7\u5f97\u6765\u6e90\u7684url\uff0cdocument.referrer;\u65b9\u6cd5\u6709\u5f88\u591a\u3002<\/p>\n<p>1\u3001\u5229\u7528pathinfo\uff1a<\/p>\n<pre>&lt;?\r\n    $test = pathinfo(\"http:\/\/localhost\/index.php\");\r\n    print_r($test);\r\n?&gt;\r\n\u7ed3\u679c\u5982\u4e0b\r\nArray\r\n(\r\n [dirname] =&gt; http:\/\/localhost \/\/url\u7684\u8def\u5f84\r\n [basename] =&gt; index.php \/\/\u5b8c\u6574\u6587\u4ef6\u540d\r\n [extension] =&gt; php \/\/\u6587\u4ef6\u540d\u540e\u7f00\r\n [filename] =&gt; index \/\/\u6587\u4ef6\u540d\r\n)\r\n\r\n\u30002\u3001\u5229\u7528parse_url()\u51fd\u6570\u89e3\u6790<\/pre>\n<pre>&lt;?\r\n    $test = parse_url(\"http:\/\/localhost\/index.php?name=tank&amp;sex=1#top\");\r\n    print_r($test);\r\n?&gt;\r\n\u7ed3\u679c\u5982\u4e0b\r\nArray\r\n(\r\n [scheme] =&gt; http \/\/\u4f7f\u7528\u4ec0\u4e48\u534f\u8bae\r\n [host] =&gt; localhost \/\/\u4e3b\u673a\u540d\r\n [path] =&gt; \/index.php \/\/\u8def\u5f84\r\n [query] =&gt; name=tank&amp;sex=1 \/\/ \u6240\u4f20\u7684\u53c2\u6570\r\n [fragment] =&gt; top \/\/\u540e\u9762\u6839\u7684\u951a\u70b9\r\n)\r\n\r\n3\u3001\u4f7f\u7528basename()\r\n\r\n<\/pre>\n<pre>&lt;?\r\n    $test = basename(\"http:\/\/localhost\/index.php?name=tank&amp;sex=1#top\");\r\n    echo $test;\r\n?&gt;\r\n\u7ed3\u679c\u5982\u4e0b\r\nindex.php?name=tank&amp;sex=1#top<\/pre>\n<p><!--more--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7url\u8fdb\u884c\u4f20\u503c\uff0c\u662fphp\u4e2d\u4e00\u4e2a\u4f20\u503c\u7684\u91cd\u8981\u624b\u6bb5\u3002\u6240\u4ee5\u6211\u4eec\u8981\u7ecf\u5e38\u5bf9url\u91cc\u9762\u6240\u5e26\u7684\u53c2\u6570\u8fdb\u884c\u89e3\u6790\uff0c\u5982\u679c\u6211\u4eec\u77e5\u9053\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=406"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":407,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/406\/revisions\/407"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}