{"id":47706,"date":"2024-12-02T16:58:44","date_gmt":"2024-12-02T08:58:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47706\/"},"modified":"2024-12-02T16:58:44","modified_gmt":"2024-12-02T08:58:44","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e6%89%a9%e5%b1%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47706\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p>PHP \u51fd\u6570\u4f18\u5316\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55\u5b9e\u73b0\uff1a\u521b\u5efa\u52a8\u6001\u6269\u5c55\u8c03\u7528\u5e95\u5c42 C \u51fd\u6570\u548c\u51cf\u5c11\u5185\u5b58\u5206\u914d\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u5229\u7528\u7f13\u5b58\u548c\u5e76\u884c\u5316\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u6548\u7387\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e\u51fd\u6570 strpos_custom \u6bd4\u539f\u751f PHP \u51fd\u6570 strpos_php \u663e\u8457\u63d0\u5347\u4e86\u901f\u5ea6\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729931673671ca9999fb87.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4f18\u5316\u6269\u5c55<\/strong><\/p>\n<p>\u4f18\u5316 PHP \u51fd\u6570\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u6269\u5c55\u4f18\u5316\u51fd\u6570\u3001\u5e76\u63d0\u4f9b\u4e00\u4e2a\u771f\u5b9e\u6848\u4f8b\u3002<\/p>\n<p><strong>\u6269\u5c55 PHP \u51fd\u6570<\/strong><\/p>\n<p>\u6269\u5c55 PHP \u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u52a8\u6001\u6269\u5c55\u6765\u5b9e\u73b0\u3002\u52a8\u6001\u6269\u5c55\u662f\u7528 C \u8bed\u8a00\u7f16\u5199\u7684\u5171\u4eab\u5e93\uff0c\u5b83\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u5230 PHP \u4e2d\u3002<\/p>\n<p>\u521b\u5efa\u52a8\u6001\u6269\u5c55\u9700\u8981\u7f16\u5199 C \u4ee3\u7801\uff0c\u7136\u540e\u7f16\u8bd1\u5b83\u6765\u521b\u5efa\u5171\u4eab\u5e93\u3002\u7136\u540e\u53ef\u4ee5\u4f7f\u7528 <code>dl()<\/code> \u51fd\u6570\u6216 <code>extension=modname<\/code> \u914d\u7f6e\u6307\u4ee4\u52a0\u8f7d\u6269\u5c55\u3002<\/p>\n<p><strong>\u4f18\u5316\u51fd\u6570<\/strong><\/p>\n<p>\u52a8\u6001\u6269\u5c55\u53ef\u4ee5\u8ba9\u60a8\u4f18\u5316 PHP \u51fd\u6570\u7684\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u5e95\u5c42\u51fd\u6570\uff1a<\/strong> \u8c03\u7528\u5e95\u5c42 C \u51fd\u6570\u53ef\u4ee5\u7ed5\u8fc7 PHP \u7684\u5f00\u9500\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>\u51cf\u5c11\u5185\u5b58\u5206\u914d\uff1a<\/strong> \u5206\u914d\u548c\u91ca\u653e\u5185\u5b58\u4f1a\u4ea7\u751f\u5f00\u9500\u3002\u901a\u8fc7\u51cf\u5c11\u5206\u914d\u6b21\u6570\u6216\u4f7f\u7528\u6301\u4e45\u5316\u6570\u636e\u7ed3\u6784\u6765\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<li><strong>\u5229\u7528\u7f13\u5b58\uff1a<\/strong> \u7f13\u5b58\u8ba1\u7b97\u7ed3\u679c\u53ef\u4ee5\u907f\u514d\u91cd\u590d\u51fd\u6570\u8c03\u7528\u3002<\/li>\n<li><strong>\u5e76\u884c\u5316\uff1a<\/strong> \u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u5e76\u884c\u5316\u8017\u65f6\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e\u51fd\u6570\u7684\u5b9e\u6218\u6848\u4f8b\uff1a<\/p>\n<p><strong>\u539f\u59cb PHP \u51fd\u6570\uff1a<\/strong><\/p>\n<pre>function strpos_php($haystack, $needle) {\n    return strpos($haystack, $needle);\n}<\/pre>\n<p><strong>\u4f18\u5316\u6269\u5c55\u51fd\u6570\uff1a<\/strong><\/p>\n<pre>#include &lt;ext\/standard\/php_str.h&gt;\n\nPHP_FUNCTION(strpos_custom) {\n    zend_string *haystack, *needle;\n    if (zend_parse_parameters(ZEND_NUM_ARGS(), \"SS\", &amp;haystack, &amp;needle) == FAILURE) {\n        RETURN_FALSE;\n    }\n\n    ZVAL_LONG(return_value, zend_string_find(haystack, needle, false, true));\n}<\/pre>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<pre>dl(\"\/path\/to\/extension.so\");\n\n$haystack = \"Hello World!\";\n$needle = \"World\";\n\n$start_time = microtime(true);\n$result_php = strpos_php($haystack, $needle);\n$end_time_php = microtime(true);\n\n$start_time_custom = microtime(true);\n$result_custom = strpos_custom($haystack, $needle);\n$end_time_custom = microtime(true);\n\necho \"PHP Function Time: \" . ($end_time_php - $start_time_php) . \"\\n\";\necho \"Custom Function Time: \" . ($end_time_custom - $start_time_custom) . \"\\n\";<\/pre>\n<p>\u5728\u8fd9\u4e2a\u6848\u4f8b\u4e2d\uff0c<code>strpos_custom<\/code> \u51fd\u6570\u6bd4\u539f\u59cb PHP \u51fd\u6570\u5feb\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP \u51fd\u6570\u5982\u4f55\u4f18\u5316\u6269\u5c55\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ PHP \u51fd\u6570\u4f18\u5316\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55\u5b9e\u73b0\uff1a\u521b\u5efa\u52a8\u6001\u6269\u5c55\u8c03\u7528\u5e95\u5c42 C \u51fd\u6570\u548c\u51cf\u5c11\u5185\u5b58\u5206\u914d\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u5229\u7528\u7f13\u5b58\u548c\u5e76\u884c\u5316\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u6548\u7387\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e\u51fd\u6570 strpos_custom \u6bd4\u539f\u751f PHP \u51fd\u6570 strpos_php \u663e\u8457\u63d0\u5347\u4e86\u901f\u5ea6\u3002 PHP \u51fd\u6570\u4f18\u5316\u6269\u5c55 \u4f18\u5316 PHP \u51fd\u6570\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u6269\u5c55\u4f18\u5316\u51fd\u6570\u3001\u5e76\u63d0\u4f9b\u4e00\u4e2a\u771f\u5b9e\u6848\u4f8b\u3002 \u6269\u5c55 PHP \u51fd\u6570 \u6269\u5c55 PHP \u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u52a8\u6001\u6269\u5c55\u6765\u5b9e\u73b0\u3002\u52a8\u6001\u6269\u5c55\u662f\u7528 C \u8bed\u8a00\u7f16\u5199\u7684\u5171\u4eab\u5e93\uff0c\u5b83\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u5230 PHP \u4e2d\u3002 \u521b\u5efa\u52a8\u6001\u6269\u5c55\u9700\u8981\u7f16\u5199 C \u4ee3\u7801\uff0c\u7136\u540e\u7f16\u8bd1\u5b83\u6765\u521b\u5efa\u5171\u4eab\u5e93\u3002\u7136\u540e\u53ef\u4ee5\u4f7f\u7528 dl() \u51fd\u6570\u6216 extension=modname \u914d\u7f6e\u6307\u4ee4\u52a0\u8f7d\u6269\u5c55\u3002 \u4f18\u5316\u51fd\u6570 \u52a8\u6001\u6269\u5c55\u53ef\u4ee5\u8ba9\u60a8\u4f18\u5316 PHP \u51fd\u6570\u7684\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u65b9\u6cd5\uff1a \u4f7f\u7528\u5e95\u5c42\u51fd\u6570\uff1a \u8c03\u7528\u5e95\u5c42 C \u51fd\u6570\u53ef\u4ee5\u7ed5\u8fc7 PHP \u7684\u5f00\u9500\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002 \u51cf\u5c11\u5185\u5b58\u5206\u914d\uff1a \u5206\u914d\u548c\u91ca\u653e\u5185\u5b58\u4f1a\u4ea7\u751f\u5f00\u9500\u3002\u901a\u8fc7\u51cf\u5c11\u5206\u914d\u6b21\u6570\u6216\u4f7f\u7528\u6301\u4e45\u5316\u6570\u636e\u7ed3\u6784\u6765\u4f18\u5316\u6027\u80fd\u3002 \u5229\u7528\u7f13\u5b58\uff1a \u7f13\u5b58\u8ba1\u7b97\u7ed3\u679c\u53ef\u4ee5\u907f\u514d\u91cd\u590d\u51fd\u6570\u8c03\u7528\u3002 \u5e76\u884c\u5316\uff1a \u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u5e76\u884c\u5316\u8017\u65f6\u64cd\u4f5c\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f18\u5316\u5b57\u7b26\u4e32\u67e5\u627e\u51fd\u6570\u7684\u5b9e\u6218\u6848\u4f8b\uff1a \u539f\u59cb [&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-47706","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47706","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=47706"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47706\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}