php - how can i get rid of extra space in explode statement -
php code
$testcases1 = explode(" ",$_post['testcases']); $num1 = $testcases1[0]; $num2 = $testcases1[1]; echo "count-"count($testcases1); echo "num2-"$num2;
correct
i/p : 3 2 o/p : count-2 num2-2
my issue
i/p : 3(just single space) o/p : count-2 num2-
and $num2 behaving has value 0 can ...
num2 can 0 100... how acheive this
i think issue $_post['testcases']
contain trailing white space.
you should trim $_post['testcases']
, explodes correctly. alter first line to:
$testcases1 = explode(" ",trim($_post['testcases']));
Comments
Post a Comment