{"id":2637,"date":"2020-04-01T15:53:54","date_gmt":"2020-04-01T14:53:54","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2637"},"modified":"2023-03-17T15:33:41","modified_gmt":"2023-03-17T15:33:41","slug":"using-strings-replace-and-insert","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/strings\/using-strings-replace-and-insert","title":{"rendered":"Using Strings-Replace and Insert"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Replace<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyString = str_replace('ReplaceThis', 'WithThis', $MyString);\n\n$domain = str_replace('www.', '', $domain);     \/\/Remove leading www. from $domain<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Case insensitive<\/h5>\n\n\n\n<p>str_ireplace() is a case-insensitive version of str_replace()<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyString= str_ireplace(\"one\", \"1\", $MyString);    \/\/Replace \"OnE\" with \"1\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Replace whitespace<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Replace single and multiple occurrences of white space with a comma<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyString= preg_replace('\/\\s+\/', ',', $MyString);    \/\/Replace single and multiple occurrence of white space with a comma<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Pad string to fixed length<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyString = \"Apple\"\n$RequiredLength = 26;\n$PadWithString = \"*~*\"\n$MyString = str_pad($MyString, $RequiredLength, $PadWithString, STR_PAD_BOTH);\n  \/\/Will give: \"*~**~**~**Apple*~**~**~**~\"\n\n$MyString = str_pad($MyString, $RequiredLength, $PadWithString, STR_PAD_RIGHT);\n  \/\/Will give: \"Apple*~**~**~**~**~**~**~*\"\n\n$MyString = str_pad($MyString, $RequiredLength, \" \", STR_PAD_RIGHT);\n  \/\/Will give: \"Apple                     \"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Replace Case insensitive str_ireplace() is a case-insensitive version of str_replace() Replace whitespace Replace single and multiple occurrences of white space with a comma Pad string to fixed length<\/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-2637","post","type-post","status-publish","format-standard","hentry","category-strings"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2637","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=2637"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2637\/revisions"}],"predecessor-version":[{"id":4486,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2637\/revisions\/4486"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}