PHP floatval,intval,substr没有正确返回值

时间:2012-02-02 02:33:08

标签: php mysql coordinates substring

<?php
$Content = "0968571.0569875198.740756475689345823327000000000465735639486589346538946589236587";
echo floatval(substr($Content, 5, 14))."<br />";
echo floatval(substr($Content, 16, 25))."<br />";
echo substr($Content, 27, 37)."<br />";
?>

为什么这段代码会返回

71.0569875198
98.740756475689
5689345823327000000000465735639486589

什么时候应该返回

71.056987
98.740756
5689345823

这只是一个测试数据!

1 个答案:

答案 0 :(得分:5)

substr(string $ string,int $ start [,int $ length ])

我认为你想象它的startIndex和endIndex就像子串的java版本一样。

你可能意味着:

echo floatval(substr($Content, 5, 14 - 5))."<br />";
echo floatval(substr($Content, 16, 25 - 16))."<br />";
echo substr($Content, 27, 37 -27)."<br />";