html - TextArea to Array with PHP -
i'm trying figure out how convert html textarea php array,
i've used form post deliver query php script, , php file getting them following line:
$ids = array($_post['ids']);
needless puts 1 line
array ( [0] => line1 line2 line3 line4 )
i need final results replace this:
$numbers = array( "line1", "line2", "line3", "line4" );
what best approach divide , re-parse ?
using explode on \n
proper way new lines. keep in mind though on platforms end of line send \r\n
, exploding on \n
leave data on end of each line.
my suggestion remove \r
before exploding, dont have loop through entire array trim result. last improvement, dont know there $_post['ids']
, check first.
<? $input = isset($_post['ids'])?$_post['ids']:""; //i dont check empty() incase app allows 0 id. if (strlen($input)==0) { echo 'no input'; exit; } $ids = explode("\n", str_replace("\r", "", $input)); ?>
Comments
Post a Comment