In PHP, how to save words separated by space and lines and put words in array -
i need help. have variable name $thetextstring contain 9 words separated line breaks , spaces fetched html form.
$thetextstring = "alpha bravo charlie delta echo foxtrot golf hotel india" ;
how can tokenize php string $thetextstring remove lines , spaces , put 9 words inside array this
$thetextarray[0] = "alpha"; $thetextarray[1] = "bravo"; $thetextarray[2] = "charlie"; $thetextarray[3] = "delta"; $thetextarray[4] = "echo"; $thetextarray[5] = "foxtrot"; $thetextarray[6] = "golf"; $thetextarray[7] = "hotel"; $thetextarray[8] = "india";
i need php code handle this. thank in advance!
here want, removed additional new line , space.
$thetextstring = "alpha bravo charlie delta echo foxtrot golf hotel india" ; $thetextstring = preg_replace("#[\s]+#", " ", $thetextstring); $words = explode(" ", $thetextstring); print_r($words); ( [0] => alpha [1] => bravo [2] => charlie [3] => delta [4] => echo [5] => foxtrot [6] => golf [7] => hotel [8] => india )
Comments
Post a Comment