{"id":48089,"date":"2024-12-02T09:22:10","date_gmt":"2024-12-02T01:22:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48089\/"},"modified":"2024-12-02T09:22:10","modified_gmt":"2024-12-02T01:22:10","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e7%bd%91%e7%bb%9c%e8%b0%83%e7%94%a8%e5%a4%96%e9%83%a8%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48089\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f<\/h1>\n<p>\u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aPHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1729988010671d85aacfb14.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1aPHP \u51fd\u6570\uff08\u5e26\u5b9e\u6218\u6848\u4f8b\uff09<\/strong><\/p>\n<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u51fd\u6570 <code>file_get_contents()<\/code>\uff0c\u5b83\u5141\u8bb8\u4f60\u4ece\u8fdc\u7a0b URL \u83b7\u53d6\u6570\u636e\u3002\u901a\u8fc7\u5229\u7528\u6b64\u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\u3002<\/p>\n<p><strong>\u65b9\u6cd5<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 <code>file_get_contents()<\/code> \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1a<\/p>\n<pre>\/\/ \u5b9a\u4e49\u5916\u90e8\u51fd\u6570\u7684 URL\n$url = 'https:\/\/example.com\/external-function.php';\n\n\/\/ \u4f7f\u7528 file_get_contents() \u8fdc\u7a0b\u83b7\u53d6\u51fd\u6570\u4ee3\u7801\n$code = file_get_contents($url);\n\n\/\/ \u5305\u542b\u8fdc\u7a0b\u51fd\u6570\u4ee3\u7801\neval($code);\n\n\/\/ \u8c03\u7528\u5916\u90e8\u51fd\u6570\n$result = external_function();<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8ba9\u6211\u4eec\u7528\u4e00\u4e2a\u5b9e\u9645\u4f8b\u5b50\u6765\u8bf4\u660e\u8fd9\u4e00\u70b9\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u4f4d\u4e8e <code>https:\/\/example.com\/external-function.php<\/code> \u7684\u5916\u90e8\u51fd\u6570\uff0c\u540d\u4e3a <code>addNumbers()<\/code>:<\/p>\n<pre>\/\/ external-function.php\n\n&lt;?php\nfunction addNumbers($a, $b) {\n  return $a + $b;\n}\n?&gt;<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>file_get_contents()<\/code> \u8c03\u7528\u6b64\u5916\u90e8\u51fd\u6570\uff1a<\/p>\n<pre>\/\/ \u5728\u4f60\u7684 PHP \u811a\u672c\u4e2d\n\n$result = file_get_contents('https:\/\/example.com\/external-function.php');\neval($result);\n\necho addNumbers(10, 20); \/\/ \u8f93\u51fa 30<\/pre>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5916\u90e8\u51fd\u6570\u662f\u53ef\u4ee5\u516c\u5f00\u8bbf\u95ee\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5fc5\u987b\u88ab\u653e\u7f6e\u5728\u516c\u5171 Web \u670d\u52a1\u5668\u4e0a\u3002<\/li>\n<li><code>eval()<\/code> \u51fd\u6570\u4f7f\u7528\u8c28\u614e\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u4f1a\u6267\u884c\u6076\u610f\u4ee3\u7801\u3002<\/li>\n<li>\u5bf9\u4e8e\u5b89\u5168\u76ee\u7684\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528 <code>fopen()<\/code> \u548c <code>fread()<\/code> \u800c\u4e0d\u662f <code>file_get_contents()<\/code>.<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u4f7f\u7528 PHP \u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f \u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aPHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1aPHP \u51fd\u6570\uff08\u5e26\u5b9e\u6218\u6848\u4f8b\uff09 \u524d\u8a00 PHP \u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u51fd\u6570 file_get_contents()\uff0c\u5b83\u5141\u8bb8\u4f60\u4ece\u8fdc\u7a0b URL \u83b7\u53d6\u6570\u636e\u3002\u901a\u8fc7\u5229\u7528\u6b64\u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8c03\u7528\u5916\u90e8\u51fd\u6570\u3002 \u65b9\u6cd5 \u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 file_get_contents() \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff1a \/\/ \u5b9a\u4e49\u5916\u90e8\u51fd\u6570\u7684 URL $url = &#8216;https:\/\/example.com\/external-function.php&#8217;; \/\/ \u4f7f\u7528 file_get_contents() \u8fdc\u7a0b\u83b7\u53d6\u51fd\u6570\u4ee3\u7801 $code = file_get_contents($url); \/\/ \u5305\u542b\u8fdc\u7a0b\u51fd\u6570\u4ee3\u7801 eval($code); \/\/ \u8c03\u7528\u5916\u90e8\u51fd\u6570 $result = external_function(); \u5b9e\u6218\u6848\u4f8b \u8ba9\u6211\u4eec\u7528\u4e00\u4e2a\u5b9e\u9645\u4f8b\u5b50\u6765\u8bf4\u660e\u8fd9\u4e00\u70b9\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u4f4d\u4e8e https:\/\/example.com\/external-function.php \u7684\u5916\u90e8\u51fd\u6570\uff0c\u540d\u4e3a addNumbers(): \/\/ external-function.php &lt;?php function addNumbers($a, $b) { return $a + $b; } ?&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48089","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48089"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48089\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}