{"id":1969,"date":"2019-01-31T17:23:39","date_gmt":"2019-01-31T17:23:39","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1969"},"modified":"2025-04-17T19:42:12","modified_gmt":"2025-04-17T18:42:12","slug":"convert-strings-to-array","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/strings\/convert-strings-to-array","title":{"rendered":"Convert Strings to Array"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Convert comma separated string into array<\/h4>\n\n\n\n<p>See dedicated page <a href=\"\/cloud\/php\/strings\/comma-separated-strings\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    $MyCommaSeperatedString = rtrim(trim(\"abc,def,ghi,\"), \",\");      \/\/Ensure there is no trailing comma\n    $MyArray = explode(',', $MyCommaSeperatedString);    \/\/Convert to array (No commas will result in the text in the string being in an array of length 1)\n    print_r($MyArray);\n    \/\/Will output: Array ( &#91;0] => abc &#91;1] => def &#91;2] => ghi )<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert array to comma separated string<\/h4>\n\n\n\n<p>See dedicated page <a href=\"https:\/\/ibex.tech\/cloud\/php\/strings\/comma-separated-strings\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyCommaSeperatedString = implode(',', $MyArray);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert string to byte array<br><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $my_memory_array = array_slice(unpack('C*', \"\\0\".$my_string), 1);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">json encode<\/h4>\n\n\n\n<p><a href=\"https:\/\/ibex.tech\/cloud\/php\/json\/json-encode\">See here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Convert comma separated string into array See dedicated page here. Convert array to comma separated string See dedicated page here. Convert string to byte array json encode See here<\/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-1969","post","type-post","status-publish","format-standard","hentry","category-strings"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1969","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=1969"}],"version-history":[{"count":8,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1969\/revisions"}],"predecessor-version":[{"id":4916,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1969\/revisions\/4916"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}