{"id":2626,"date":"2020-04-01T15:47:38","date_gmt":"2020-04-01T14:47:38","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2626"},"modified":"2025-04-09T11:35:46","modified_gmt":"2025-04-09T10:35:46","slug":"using-strings-searching-strings","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/strings\/using-strings-searching-strings","title":{"rendered":"Using Strings-Searching Strings"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Does String Contain String<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">str_contains<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (str_contains($MyString, 'hello'))    \/\/Returns true or false\n  {\n    echo 'true';\n  }<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">strpos()<\/h5>\n\n\n\n<p>strpos ($haystack , $needle , $offset = 0 ) <\/p>\n\n\n\n<p>Returns False on no match or first occurrence index (from 0) on match<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (strpos($MyString, 'hello') !== False)\n  {\n    echo 'true';\n  }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  $char_index = strpos( strtolower($StringToCheck), &nbsp;strtolower($LookingForString));\t\t\/\/Using strtolower() removes case sensitivity\n  if($char_index === false)\n  {\n    \/\/Not found\n  }\n  else\n  {\n    \/\/Found\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Does string start with<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (str_starts_with($StringToCheck, $LookingForString))     \/\/True if it starts with, false otherwise<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Does string end with<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (str_ends_with($StringToCheck, $LookingForString))     \/\/True if it ends with, false otherwise<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Does String Contain String str_contains strpos() strpos ($haystack , $needle , $offset = 0 ) Returns False on no match or first occurrence index (from 0) on match Does string start with Does string end with<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-2626","post","type-post","status-publish","format-standard","hentry","category-strings"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2626"}],"version-history":[{"count":10,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2626\/revisions"}],"predecessor-version":[{"id":4848,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2626\/revisions\/4848"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}