2 回答
TA贡献1828条经验 获得超3个赞
在 PHP 中比较浮点值可能会有问题。如果这是您所要求的,您可以使用 bccomp() 来比较浮点值。
$a = '59.68000';
$b = '59.85000';
echo between($a, $b, '59.68001') . "\n"; // in range
echo between($a, $b, '59.68000') . "\n"; // exact match
echo between($a, $b, '59.88000') . "\n"; // higher than range
echo between($a, $b, '59.67000') . "\n"; // lower than range
function between($lower, $upper, $value)
{
// Value is greater than lower bound of range
$check1 = bccomp($value, $lower, 6) >= 0;
// Value is less than upper bounds of range
$check2 = bccomp($upper, $value, 6) >= 0;
if ( $check1 && $check2 ) {
return true;
}
return false;
}
使用功能:
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=601') as $f ) {
if (strpos($f->title, $title) !== false) {
$long = $f->children('georss', true)->children('gml', true)->children('gml', true);
$lat = $f->lattitude_value(); // Replace me!!
if ( between('59.68000', '59.85000', $long) && between('5.510000', '8.750000', $lat) ) {
echo $long . ' ' . $lat . "<br>";
}
}
}
TA贡献1111条经验 获得超0个赞
我到处玩,发现这是解决我的问题的最佳方法:
foreach(Feed($url) as $f ) {
if (strpos($f->title, $title) !== false){
$pos = $f->children('georss', true)->children('gml', true)->children('gml', true);
list($number1, $number2) = explode(' ', $pos);
if ($number1 > 50.00000 && $number1 < 71.00000){
if ($number2 > 4.510000 && $number2 < 10.750000){
echo $f->children('georss', true)->children('gml', true)->children('gml', true). "<br>";
}
}
}
}
- 2 回答
- 0 关注
- 116 浏览
添加回答
举报