{"id":714,"date":"2017-02-17T09:54:57","date_gmt":"2017-02-17T17:54:57","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=714"},"modified":"2017-02-17T09:55:30","modified_gmt":"2017-02-17T17:55:30","slug":"find-a-substring-within-a-string-and-return-the-index-where-it-was-found","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=714","title":{"rendered":"Find a substring within a string and return the index where it was found"},"content":{"rendered":"<pre>\r\n\r\n$bigString = \"I am a really big realtor in the bay area\";\r\n$pattern = \"realtor\";\r\n\r\n$i = 0;\r\n$j = 0;\r\n$bigStringLen = strlen($bigString);\r\n$patternLen = strlen($pattern);\r\n$found = false;\r\nwhile ($i <= ($bigStringLen - $patternLen)) {\r\n   if ($bigString[$i] == $pattern[$j]) {\r\n\r\n   } else {\r\n       $j=0;\r\n   }\r\n   $i++; $j++;\r\n   if ($j >= $patternLen) {\r\n       $found = true;\r\n       break;\r\n   }\r\n}\r\nif ($found) {\r\n    print \"found at \" . ($i-$patternLen) . \"\\n\";\r\n} else {\r\n    echo \"\\nnot found\\n\";\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$bigString = &#8220;I am a really big realtor in the bay area&#8221;; $pattern = &#8220;realtor&#8221;; $i = 0; $j = 0; $bigStringLen = strlen($bigString); $patternLen = strlen($pattern); $found = false; while ($i = $patternLen) { $found = true; break; } } if ($found) { print &#8220;found at &#8221; . ($i-$patternLen) . &#8220;\\n&#8221;; } else { &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=714\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Find a substring within a string and return the index where it was found<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-714","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=714"}],"version-history":[{"count":2,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":716,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions\/716"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}