{"id":18,"date":"2014-07-03T15:38:50","date_gmt":"2014-07-03T15:38:50","guid":{"rendered":"https:\/\/jmrowe.com\/blog\/?p=18"},"modified":"2014-07-03T15:53:51","modified_gmt":"2014-07-03T15:53:51","slug":"creating-an-array-from-a-list-of-items-in-a-_post-variable","status":"publish","type":"post","link":"https:\/\/jmrowe.com\/blog\/creating-an-array-from-a-list-of-items-in-a-_post-variable\/","title":{"rendered":"Creating an array from a list of items in a $_POST variable"},"content":{"rendered":"<p>Routinely, I&#8217;ll find my self creating forms that will take a list of items in a textarea that was pasted from another program\u00a0like Excel ( column of data ). Furthermore, I will usually take this list of data and explode it into an array to be processed individually.<\/p>\n<p>Using the explode function in php is simple, however, when separating items in the $_POST array by a newline &#8211; the newline may be different based on the type of php server.<\/p>\n<p><code>\\n<\/code>\u00a0is used for Unix systems (including Linux, and OSX).<\/p>\n<p><code>\\r\\n<\/code>\u00a0is mainly used on Windows.<\/p>\n<p style=\"color: #000000;\"><code>\\r<\/code>\u00a0is used on really old Macs.<\/p>\n<p style=\"color: #000000;\">To avoid these differences, you can use the php constant PHP_EOL .<\/p>\n<p style=\"color: #000000;\">If we had a textarea named &#8220;list&#8221; &#8211; then it would look like:<\/p>\n<pre class=\"lang:php decode:true \">$items=explode(PHP_EOL,$_POST['list']);<\/pre>\n<p>&nbsp;<\/p>\n<p style=\"color: #000000;\">\n","protected":false},"excerpt":{"rendered":"<p>Routinely, I&#8217;ll find my self creating forms that will take a list of items in a textarea that was pasted from another program\u00a0like Excel ( column of data ). Furthermore, I will usually take this list of data and explode it into an array to be processed individually. Using the explode function in php is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":3,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":21,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions\/21"}],"wp:attachment":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}