{"id":163,"date":"2023-02-18T21:31:25","date_gmt":"2023-02-18T13:31:25","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=163"},"modified":"2023-02-18T21:31:46","modified_gmt":"2023-02-18T13:31:46","slug":"php-lookup-string","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/php-lookup-string\/","title":{"rendered":"PHP\u67e5\u627e\u5b57\u7b26\u4e32"},"content":{"rendered":"<p><code>strpos()<\/code> &#8211; \u67e5\u627e\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09<br \/>\n<code>stripos()<\/code> &#8211; \u67e5\u627e\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<br \/>\n<code>strrpos()<\/code> &#8211; \u67e5\u627e\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09<br \/>\n<code>strripos()<\/code> &#8211; \u67e5\u627e\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p><!-- more --><\/p>\n<p>\u53c2\u6570\uff1a<\/p>\n<pre><code>strpos(string, find, start)<\/code><\/pre>\n<ul>\n<li>string\uff1a\u5fc5\u9700\u3002\u89c4\u5b9a\u8981\u641c\u7d22\u7684\u5b57\u7b26\u4e32<\/li>\n<li>find\uff1a\u5fc5\u9700\u3002\u89c4\u5b9a\u8981\u67e5\u627e\u7684\u5b57\u7b26<\/li>\n<li>start\uff1a\u53ef\u9009\u3002\u89c4\u5b9a\u5f00\u59cb\u641c\u7d22\u7684\u4f4d\u7f6e<\/li>\n<\/ul>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-php\">$str = &#039;abcdef&#039;;\n$find = &#039;abc&#039;;\n$pos = strpos($str, $find);\n\n\/\/ \u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528\u7684\u662f === \u4e0d\u80fd\u4f7f\u7528 ==\n\/\/ \u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u5b57\u7b26\u4e32\uff0c\u5c31\u8fd4\u56defalse\uff1b\u800c\u5982\u679c\u67e5\u627e\u7684\u5b57\u7b26\u4e32\u4f4d\u4e8e\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u4f4d\u7f6e\uff0c\u5c31\u4f1a\u8fd4\u56de0\u3002\u4e3a\u4e86\u533a\u52060\u548cfalse\u5c31\u5fc5\u987b\u4f7f\u7528\u7b49\u540c\u64cd\u4f5c\u7b26 === \u6216\u8005 !==\n\nif ($pos === false) {\n    echo &quot;$find\u4e0d\u5728$str\u4e2d&quot;;\n} else {\n    echo &quot;$find\u5728$str\u4e2d&quot;;\n}<\/code><\/pre>\n<pre><code class=\"language-php\">$str = &#039;abcdef abcdef&#039;;\n$pos = strpos($str, &#039;a&#039;, 1);  \/\/ $pos = 7, \u4e0d\u662f 0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>strpos() &#8211; \u67e5\u627e\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09 stripos()  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-php-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}