的index.php:
<form method='post' action='2.php'>
<textarea id='textBox' name='nums'></textarea>
<input type='submit' value='Submit'>
</form>
用户输入如下内容:
0.001095626
-0.000731242
0.000160805
0.000237805
-0.000319504
0.00045355
0.000610094
0.001076248
0.000106892
-0.000972782
0.000345966
0.000366043
-0.00035067
-0.001273869
-0.001499036
2.00E-05
-0.000427038
0.000167439
0.00E+00
-0.001252732
0.000426437
0.00164935
0.000421807
-9.38E-05
0.000165533
0.00010751
0.000386017
-0.000112784
-0.000254844
secondpage.php:
$outPut = $_REQUEST['nums'];
echo "</p><a href='index.php'>Back</a></p>";
$commas = str_replace("\n"," \" , \" ", $outPut);
$string = " \" " . $commas . " \" ";
echo $string;
$array = array($string);
echo $array[2];
该数组的输出是
" 0.001095626 " , " -0.000731242 " , " 0.000160805 " , " 0.000237805 " , " -0.000319504 " , " 0.00045355 " , " 0.000610094 " , " 0.001076248 " , " 0.000106892 " , " -0.000972782 " , " 0.000345966 " , " 0.000366043 " , " -0.00035067 " , " -0.001273869 " , " -0.001499036 " , " 2.00E-05 " , " -0.000427038 " , " 0.000167439 " , " 0.00E+00 " , " -0.001252732 " , " 0.000426437 " , " 0.00164935 " , " 0.000421807 " , " -9.38E-05 " , " 0.000165533 " , " 0.00010751 " , " 0.000386017 " , " -0.000112784 " , " -0.000254844 "
但我想要的是第二个变量,它应该是0.000160805
这是我的工作代码.......................................... ..
$outPut = $_REQUEST['nums'];
echo "</p><a href='index.php'>Back</a></p>";
$commas = str_replace("\n"," , ", $outPut);
$string = $commas;
$myArray = explode(',', $string);
print_r($myArray[3]);
With this input.
0.001095626
-0.000731242
0.000160805
0.000237805
-0.000319504
0.00045355
0.000610094
0.001076248
0.000106892
-0.000972782
0.000345966
0.000366043
-0.00035067
-0.001273869
-0.001499036
2.00E-05
-0.000427038
0.000167439
0.00E+00
-0.001252732
0.000426437
0.00164935
0.000421807
-9.38E-05
0.000165533
0.00010751
0.000386017
-0.000112784
-0.000254844
并且输出正确...谢谢大家!!!
0.000160805