unkwntech Posted February 22, 2010 Share Posted February 22, 2010 I have a textbox that is posting a list of items (one per line) when I attempt to split that list into an array with this code: $answers = preg_split('/[\r\n]+/', $_POST['answers'], -1, PREG_SPLIT_NO_EMPTY); where $_POST['answers'] = "red\ngreen\nblue"; `$answers` results in an empty array. I have also tried $answers = explode("\n", $_POST['answers']); which resulted in an array with a single empty element. Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted February 22, 2010 Share Posted February 22, 2010 Nope. This code $_POST['answers'] = "red\ngreen\nblue"; $answers = explode("\n", $_POST['answers']); print_r($answers); works just dandy for me...returning Array ( [0] => red [1] => green [2] => blue ) BUT: I am a freelance PHP developer. Freelance does not mean that my work is free. If I help that means I took time away from making money, please don't be grumpy. And I may or may not have tested my code, if I posted it then most likely my IDE said the syntax was correct however that does not mean that it works. I just had to throw that in there, because, you just never know when someone is gonna sue you for giving them code that doesn't work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.