{"id":726,"date":"2017-04-30T22:19:15","date_gmt":"2017-04-30T14:19:15","guid":{"rendered":"http:\/\/www.rain1024.com\/?p=726"},"modified":"2023-08-07T20:57:28","modified_gmt":"2023-08-07T12:57:28","slug":"php-article78","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2017\/04\/30\/php-article78\/","title":{"rendered":"php\u4e2d\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u5728\u5b57\u7b26\u4e32\u4e2d"},"content":{"rendered":"<p>php\u4e2d\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u5728\u5b57\u7b26\u4e32\u4e2d<br \/>\n\u4e0b\u9762\u4ecb\u7ecd\u4f7f\u7528\u65b9\u6cd5:<\/p>\n<ol>\n<li>strstr: \u8fd4\u56de\u4e00\u4e2a\u4ece\u88ab\u5224\u65ad\u5b57\u7b26\u5f00\u59cb\u5230\u7ed3\u675f\u7684\u5b57\u7b26\u4e32,\u5982\u679c\u6ca1\u6709\u8fd4\u56de\u503c,\u5219\u4e0d\u5305\u542b<br \/>\n\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code>&lt;?php \n\/*\u5982\u624b\u518c\u4e0a\u7684\u4e3e\u4f8b*\/ \n$email = 'user@example.com'; \n$domain = strstr($email, '@'); \necho $domain; \/\/ prints @example.com \n?&gt; \n<\/code><\/pre>\n<\/li>\n<li>stristr: \u5b83\u548cstrstr\u7684\u4f7f\u7528\u65b9\u6cd5\u5b8c\u5168\u4e00\u6837.\u552f\u4e00\u7684\u533a\u522b\u662fstristr\u4e0d\u533a\u5206\u5927\u5c0f\u5199.<\/p>\n<\/li>\n<li>\n<p>\u7528explode\u8fdb\u884c\u5224\u65ad<br \/>\n\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code>function checkstr($str){ \n$needle = \"a\";\/\/\u5224\u65ad\u662f\u5426\u5305\u542ba\u8fd9\u4e2a\u5b57\u7b26 \n$tmparray = explode($needle,$str); \nif(count($tmparray)&gt;1){ \nreturn true; \n} else{ \nreturn false; \n} \n}\n<\/code><\/pre>\n<\/li>\n<li>strpos: \u8fd4\u56deboolean\u503c.FALSE\u548cTRUE\u4e0d\u7528\u591a\u8bf4.\u7528 \u201c===\u201d\u8fdb\u884c\u5224\u65ad.strpos\u5728\u6267\u884c\u901f\u5ea6\u4e0a\u90fd\u6bd4\u4ee5\u4e0a\u4e24\u4e2a\u51fd\u6570\u5feb,\u53e6\u5916strpos\u6709\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u5224\u65ad\u7684\u4f4d\u7f6e,\u4f46\u662f\u9ed8\u8ba4\u4e3a\u7a7a.\u610f\u601d\u662f\u5224\u65ad\u6574\u4e2a\u5b57\u7b26\u4e32.\u7f3a\u70b9\u662f\u5bf9\u4e2d\u6587\u7684\u652f\u6301\u4e0d\u597d.\u4f7f\u7528\u65b9\u6cd5 <\/li>\n<\/ol>\n<ul>\n<li>strpos() - \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<\/p>\n<\/li>\n<li>\n<p>stripos() - \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<\/p>\n<\/li>\n<li>\n<p>strrpos() - \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<\/p>\n<\/li>\n<li>\n<p>strripos() - \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<blockquote><p>\n  \u53c2\u6570\uff1a<br \/>\n  strripos(string,find,start)<br \/>\n  string\uff1a\u5fc5\u9700\u3002\u89c4\u5b9a\u8981\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n  find\uff1a\u5fc5\u9700\u3002\u89c4\u5b9a\u8981\u67e5\u627e\u7684\u5b57\u7b26\u3002<br \/>\n  start\uff1a\u53ef\u9009\u3002\u89c4\u5b9a\u5f00\u59cb\u641c\u7d22\u7684\u4f4d\u7f6e\u3002\n<\/p><\/blockquote>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<pre><code>1#\n&lt;?php\n$str = 'abcdef';\n$find   = 'abc';\n$pos = strpos($mystring, $findme);\n\/\/ \u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528\u7684\u662f ===\u4e0d\u80fd\u4f7f\u7528==\n\/\/ \u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u5b57\u7b26\u4e32 \u5c31\u8fd4\u56defalse\uff0c\u5982\u679c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4f4d\u4e8e\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u7684\u5730\u65b9\uff0c\n\u5c31\u4f1a\u8fd4\u56de0\u4e3a\u4e86\u533a\u52060\u548cfalse\u5c31\u5fc5\u987b\u4f7f\u7528\u7b49\u540c\u64cd\u4f5c\u7b26 === \u6216\u8005 \uff01==\nif ($pos === false) {\necho \"$find\u4e0d\u5728$str\u4e2d\";\n} else {\necho \"$find\u5728$str\u4e2d\";\n}\n?&gt;\n<\/code><\/pre>\n<pre><code>2#\n<?php\n$string = 'abcdef abcdef';\n$find = strpos($string,'a',1); \/\/ $find = 7, \u4e0d\u662f 0\n?>\n<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>php\u4e2d\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u5728\u5b57\u7b26\u4e32\u4e2d \u4e0b\u9762\u4ecb\u7ecd\u4f7f\u7528\u65b9\u6cd5: strstr: \u8fd4\u56de\u4e00\u4e2a\u4ece\u88ab\u5224\u65ad\u5b57\u7b26\u5f00\u59cb\u5230\u7ed3\u675f\u7684\u5b57\u7b26\u4e32\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2017\/04\/30\/php-article78\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":575,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[57],"class_list":["post-726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":1455,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/726\/revisions\/1455"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/575"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}