{"id":202468,"date":"2025-05-13T10:54:37","date_gmt":"2025-05-13T02:54:37","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202468\/"},"modified":"2025-05-13T10:54:37","modified_gmt":"2025-05-13T02:54:37","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e4%b8%8e-kotlin-%e4%ba%a4%e4%ba%92%ef%bc%9a%e6%97%a0%e7%bc%9d%e8%bf%9e%e6%8e%a5-android-%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202468\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin \u4ea4\u4e92\uff1a\u65e0\u7f1d\u8fde\u63a5 Android \u5f00\u53d1"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin \u4ea4\u4e92\uff1a\u65e0\u7f1d\u8fde\u63a5 Android \u5f00\u53d1<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin \u4ea4\u4e92\uff1a\u65e0\u7f1d\u8fde\u63a5 Android \u5f00\u53d1\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>Kotlin \u4e0e PHP \u51fd\u6570\u4ea4\u4e92\u7684\u5173\u952e\uff1a\u4f7f\u7528 Android Process \u7c7b\u521b\u5efa\u72ec\u7acb\u8fdb\u7a0b\uff0c\u5176\u4e2d\u8fd0\u884c PHP \u4ee3\u7801\u3002\u5411 PHP \u51fd\u6570\u8f93\u5165\u6570\u636e\uff0c\u5e76\u8bfb\u53d6\u5176\u8f93\u51fa\u3002\u8fd9\u6837\uff0cKotlin \u5f00\u53d1\u8005\u53ef\u4ee5\u5229\u7528 PHP \u7684\u529f\u80fd\uff0c\u540c\u65f6\u4eab\u53d7 Kotlin \u7684\u4fbf\u6377\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729836768671b36e0abbbd.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>PHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin \u4ea4\u4e92\uff1a\u65e0\u7f1d\u8fde\u63a5 Android \u5f00\u53d1<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728\u6784\u5efa\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u7ecf\u5e38\u9700\u8981\u5728 Android \u548c PHP \u4e4b\u95f4\u4ea4\u6362\u6570\u636e\u3002PHP \u51fd\u6570\u53ef\u4ee5\u63d0\u4f9b\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7b49\u5173\u952e\u529f\u80fd\uff0c\u800c Kotlin \u4e3a Android \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5f00\u53d1\u5de5\u5177\u3002\u901a\u8fc7\u4e86\u89e3\u5982\u4f55\u5c06\u8fd9\u4e9b\u5143\u7d20\u6574\u5408\u5728\u4e00\u8d77\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u521b\u5efa\u65e0\u7f1d\u7684\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p><strong>Kotlin \u4e2d\u8c03\u7528 PHP \u51fd\u6570<\/strong><\/p>\n<p>\u8981\u4ece Kotlin \u4e2d\u8c03\u7528 PHP \u51fd\u6570\uff0c\u9700\u8981\u4f7f\u7528 Android \u7684 <code>Process<\/code> \u7c7b\u3002\u8be5\u7c7b\u5141\u8bb8\u5f00\u53d1\u8005\u521b\u5efa\u72ec\u7acb\u8fdb\u7a0b\uff0c\u5e76\u5728\u5176\u4e2d\u8fd0\u884c PHP \u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u6b65\u9aa4\uff1a<\/p>\n<pre>\/\/ \u521b\u5efa ProcessBuilder \u5e76\u8bbe\u7f6e\u547d\u4ee4\nval processBuilder = ProcessBuilder(\"php\", \"script.php\")\n\n\/\/ \u542f\u52a8\u8fdb\u7a0b\u5e76\u83b7\u53d6\u5176\u8f93\u5165\u8f93\u51fa\u6d41\nval process = processBuilder.start()\nval inputStream = process.inputStream\nval outputStream = process.outputStream\n\n\/\/ \u7f16\u5199 PHP \u51fd\u6570\u6240\u9700\u7684\u6570\u636e\nval data = \"Hello from Kotlin!\"\n\n\/\/ \u5c06\u6570\u636e\u5199\u5165 PHP \u51fd\u6570\u7684 stdin\noutputStream.write(data.toByteArray())\n\n\/\/ \u8bfb\u53d6 PHP \u51fd\u6570\u7684\u8f93\u51fa\nval output = inputStream.bufferedReader().readText()\n\n\/\/ \u5173\u95ed\u6d41\u548c\u8fdb\u7a0b\ninputStream.close()\noutputStream.close()\nprocess.destroy()<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a PHP \u51fd\u6570 <code>greet.php<\/code>\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u5e76\u8fd4\u56de\u4e00\u6761\u5e26\u6709\u8be5\u53c2\u6570\u7684\u95ee\u5019\u6d88\u606f\uff1a<\/p>\n<pre>&lt;?php\nfunction greet($name) {\n  return \"Hello, $name!\";\n}<\/pre>\n<p>\u8981\u5728 Kotlin \u4e2d\u8c03\u7528\u6b64\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<pre>val name = \"John\"\nval processBuilder = ProcessBuilder(\"php\", \"greet.php\")\nval process = processBuilder.start()\nval inputStream = process.inputStream\nval outputStream = process.outputStream\noutputStream.write(name.toByteArray())\nval output = inputStream.bufferedReader().readText()\nprintln(output) \/\/ \u8f93\u51fa: Hello, John!<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528 <code>Process<\/code> \u7c7b\uff0cKotlin \u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u8c03\u7528 PHP \u51fd\u6570\u5e76\u4e0e\u5176\u4ea4\u4e92\u3002\u8fd9\u79cd\u6280\u672f\u5728\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u5229\u7528 PHP \u7684\u529f\u80fd\uff0c\u540c\u65f6\u5229\u7528 Kotlin \u7684\u4fbf\u6377\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin \u4ea4\u4e92\uff1a\u65e0\u7f1d\u8fde\u63a5 Android \u5f00\u53d1\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,kotlin\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u4e0e Kotlin&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202468","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202468"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202468\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}