{"id":46947,"date":"2024-12-02T09:44:25","date_gmt":"2024-12-02T01:44:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46947\/"},"modified":"2024-12-02T09:44:25","modified_gmt":"2024-12-02T01:44:25","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e6%89%a9%e5%b1%95%e5%88%b0%e5%85%b6%e4%bb%96%e8%af%ad%e8%a8%80%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46947\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u521b\u5efa PHP \u6269\u5c55\uff08\u4f7f\u7528 C \u8bed\u8a00\u7f16\u5199\u4ee3\u7801\uff09\u7f16\u8bd1\u548c\u5b89\u88c5\u6269\u5c55\u5728\u76ee\u6807\u8bed\u8a00\u4e2d\u52a0\u8f7d\u6269\u5c55\uff08\u5982 Java\uff09\u8c03\u7528 PHP \u51fd\u6570\uff08\u5982 Java \u4e2d\u7684 php_extension_str_rot13\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729856433671b83b13e982.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1a\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>PHP \u662f\u4e00\u79cd\u6d41\u884c\u7684\u670d\u52a1\u5668\u7aef\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8e\u521b\u5efa\u52a8\u6001 web \u5e94\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u6709\u65f6\u9700\u8981\u5728 PHP \u5e94\u7528\u7a0b\u5e8f\u4e4b\u5916\u4f7f\u7528 PHP \u51fd\u6570\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55 PHP \u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u6269\u5c55\u673a\u5236<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u51e0\u79cd\u6269\u5c55\u673a\u5236\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5c06\u81ea\u5b9a\u4e49\u51fd\u6570\u6dfb\u52a0\u5230\u8bed\u8a00\u4e2d\u3002\u8fd9\u4e9b\u673a\u5236\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>Zend \u6269\u5c55 (ZEND_EXTENSION)<\/strong>\uff1a\u6b64\u673a\u5236\u5141\u8bb8\u60a8\u4f7f\u7528 C \u8bed\u8a00\u521b\u5efa PHP \u6269\u5c55\u3002<\/li>\n<li><strong>PHP \u6269\u5c55\u5305 (PECL)<\/strong>\uff1aPECL \u662f\u4e00\u4e2a\u6269\u5c55\u5e93\uff0c\u63d0\u4f9b\u9884\u7f16\u8bd1\u7684 PHP \u6269\u5c55\u3002<\/li>\n<li><strong>PHP \u5185\u6838\u6a21\u5757 (PHP_MODULE)<\/strong>\uff1a\u6b64\u673a\u5236\u5141\u8bb8\u60a8\u4f7f\u7528 PHP \u8bed\u8a00\u672c\u8eab\u521b\u5efa PHP \u6269\u5c55\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u5411 Java \u6269\u5c55\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570<\/strong><\/p>\n<p>\u8ba9\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\u6765\u4e86\u89e3\u5982\u4f55\u5411\u5176\u4ed6\u8bed\u8a00\u6269\u5c55 PHP \u51fd\u6570\u3002\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a PHP \u6269\u5c55\u6765\u5411 Java \u5e94\u7528\u7a0b\u5e8f\u516c\u5f00 PHP \u7684\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u521b\u5efa PHP \u6269\u5c55<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa PHP \u6269\u5c55\uff1a<\/p>\n<pre>pecl install -o extension=my_php_extension.so php_my_extension<\/pre>\n<p><strong>\u6b65\u9aa4 2\uff1a\u7f16\u5199 PHP \u6269\u5c55\u4ee3\u7801<\/strong><\/p>\n<p>\u5728 <code>php_my_extension.c<\/code> \u4e2d\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>#include &lt;php.h&gt;\n#include &lt;zend_extensions.h&gt;\n\nZEND_FUNCTION(php_extension_str_rot13) {\n  char *str, *encoded;\n  int len, i;\n  \n  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \"s\", &amp;str) == FAILURE) {\n    RETURN_NULL();\n  }\n\n  len = strlen(str);\n  encoded = malloc(len + 1);\n\n  for (i = 0; i &lt; len; i++) {\n    encoded[i] = str[i];\n    \n    if (str[i] &gt;= 'a' &amp;&amp; str[i] &lt;= 'z') {\n      encoded[i] = (str[i] - 'a' + 13) % 26 + 'a';\n    } else if (str[i] &gt;= 'A' &amp;&amp; str[i] &lt;= 'Z') {\n      encoded[i] = (str[i] - 'A' + 13) % 26 + 'A';\n    }\n  }\n\n  encoded[len] = '\\0';\n  RETURN_STRING(encoded, 1);\n}\n\nZEND_MODULE_STARTUP_FUNCTION(my_php_extension) {\n  zend_function_entry functions[] = {\n    { \"str_rot13\", ZEND_FN(php_extension_str_rot13), 1, ZEND_MODULE_PERSISTENT },\n    { NULL, NULL, NULL} \n  };\n  \n  zend_register_module_entry(\"my_php_extension\", functions, NULL, NULL, NULL, NULL, NULL, NULL);\n\n  RETURN_SUCCESS;\n}<\/pre>\n<p><strong>\u6b65\u9aa4 3\uff1a\u7f16\u8bd1\u548c\u5b89\u88c5 PHP \u6269\u5c55<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u548c\u5b89\u88c5 PHP \u6269\u5c55\uff1a<\/p>\n<pre>phpize\n.\/configure\nmake\nmake install<\/pre>\n<p><strong>\u6b65\u9aa4 4\uff1a\u5728 Java \u4e2d\u4f7f\u7528 PHP \u51fd\u6570<\/strong><\/p>\n<p>\u73b0\u5728\u53ef\u4ee5\u5728 Java \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 <code>php_extension_str_rot13<\/code> \u51fd\u6570\u3002\u4e3a\u6b64\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u5c06 <code>php_my_extension.so<\/code> \u590d\u5236\u5230 Java \u5e94\u7528\u7a0b\u5e8f\u7684\u7c7b\u8def\u5f84\u4e2d\u3002<\/li>\n<li>\n<p>\u52a0\u8f7d PHP \u6269\u5c55\uff1a<\/p>\n<pre>System.loadLibrary(\"php_my_extension\");<\/pre>\n<\/li>\n<li>\n<p>\u8c03\u7528 <code>php_extension_str_rot13<\/code> \u51fd\u6570\uff1a<\/p>\n<pre>String str = \"Hello, world!\";\nString encoded = php_extension_str_rot13(str);\nSystem.out.println(encoded); \/\/ Output: Uryyb, jbeyq!<\/pre>\n<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u6269\u5c55\u673a\u5236\uff0c\u60a8\u53ef\u4ee5\u5c06 PHP \u51fd\u6570\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff0c\u4ece\u800c\u80fd\u591f\u8f7b\u677e\u5730\u5c06 PHP \u7684\u529f\u80fd\u96c6\u6210\u5230\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u672c\u6587\u4e2d\u7684 Java \u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u6269\u5c55 PHP \u7684\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u5e76\u5c06\u5176\u7528\u4f5c Java \u4ee3\u7801\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,\u6269\u5c55\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 PHP \u51fd\u6570\u6269\u5c55\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u521b\u5efa PHP \u6269\u5c55\uff08\u4f7f\u7528 C \u8bed\u8a00\u7f16\u5199\u4ee3\u7801\uff09\u7f16\u8bd1\u548c\u5b89\u88c5\u6269\u5c55\u5728\u76ee\u6807\u8bed\u8a00\u4e2d\u52a0\u8f7d\u6269\u5c55\uff08\u5982 Java\uff09\u8c03\u7528 PHP \u51fd\u6570\uff08\u5982 Java \u4e2d\u7684 php_extension_str_rot13\uff09 PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5176\u4ed6\u8bed\u8a00\uff1a\u5b9e\u6218\u6848\u4f8b \u5f15\u8a00 PHP \u662f\u4e00\u79cd\u6d41\u884c\u7684\u670d\u52a1\u5668\u7aef\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8e\u521b\u5efa\u52a8\u6001 web \u5e94\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u6709\u65f6\u9700\u8981\u5728 PHP \u5e94\u7528\u7a0b\u5e8f\u4e4b\u5916\u4f7f\u7528 PHP \u51fd\u6570\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55 PHP \u51fd\u6570\u6765\u5b9e\u73b0\u3002 \u6269\u5c55\u673a\u5236 PHP \u63d0\u4f9b\u4e86\u51e0\u79cd\u6269\u5c55\u673a\u5236\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5c06\u81ea\u5b9a\u4e49\u51fd\u6570\u6dfb\u52a0\u5230\u8bed\u8a00\u4e2d\u3002\u8fd9\u4e9b\u673a\u5236\u5305\u62ec\uff1a Zend \u6269\u5c55 (ZEND_EXTENSION)\uff1a\u6b64\u673a\u5236\u5141\u8bb8\u60a8\u4f7f\u7528 C \u8bed\u8a00\u521b\u5efa PHP \u6269\u5c55\u3002 PHP \u6269\u5c55\u5305 (PECL)\uff1aPECL \u662f\u4e00\u4e2a\u6269\u5c55\u5e93\uff0c\u63d0\u4f9b\u9884\u7f16\u8bd1\u7684 PHP \u6269\u5c55\u3002 PHP \u5185\u6838\u6a21\u5757 (PHP_MODULE)\uff1a\u6b64\u673a\u5236\u5141\u8bb8\u60a8\u4f7f\u7528 PHP \u8bed\u8a00\u672c\u8eab\u521b\u5efa PHP \u6269\u5c55\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a\u5411 Java \u6269\u5c55\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570 [&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-46947","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46947","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=46947"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46947\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}