spires Posted June 10, 2011 Share Posted June 10, 2011 Hi I'm trying to separate each line of a text filed and place each line in to an array one by one. At the moment i'm just trying get echo out the count of how many items a are in the array $expKey; When entering the words in the text field, i'm pressing return to move doen to the next line. I'm adding 4 lines of text. So, the count should be 4. Or am I missing something? $expKey = explode("/n", $_POST['keywords']); echo count($expKey). ' '; Thanks Link to comment https://forums.phpfreaks.com/topic/238988-array-help-needed/ Share on other sites More sharing options...
spires Posted June 10, 2011 Author Share Posted June 10, 2011 OK, I have a work around, but i'm sure the other way should work fine. So, if you have another / better way to do it, please let me know. Work Around $expKey = explode("<br />", nl2br($_POST['key_'.$i])); Link to comment https://forums.phpfreaks.com/topic/238988-array-help-needed/#findComment-1227985 Share on other sites More sharing options...
WebStyles Posted June 11, 2011 Share Posted June 11, 2011 this: $expKey = explode("/n", $_POST['keywords']); does not work, because the correct newline character is "\n" and not "/n" Link to comment https://forums.phpfreaks.com/topic/238988-array-help-needed/#findComment-1228170 Share on other sites More sharing options...
mikesta707 Posted June 11, 2011 Share Posted June 11, 2011 just use file() This takes a file and returns an array of each different line, which is exactly what you want if im not mistaken EDIT: Sorry misread your post. Yeah you are using the wrong newline character (\n not /n) as webstyles pointed out Link to comment https://forums.phpfreaks.com/topic/238988-array-help-needed/#findComment-1228178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.