Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用于匹配纬度和经度函数的正则表达式_Php_Function_Preg Replace - Fatal编程技术网

Php 用于匹配纬度和经度函数的正则表达式

Php 用于匹配纬度和经度函数的正则表达式,php,function,preg-replace,Php,Function,Preg Replace,我的文件中有一个纬度和经度数据,我正试图通过 我试图为$result60行添加函数,但它不起作用。我试图传递函数的值,因此它将使用DM方法计算正确的纬度和经度 企图 如何解决此问题?您可以使用DMS方法将输入字符串分为3组,其中组$1、$2和$3可以被调用以返回$decimal 正则表达式 代码 “当我试图为$result60=..行添加函数时”是什么意思?你能用更详细的信息和你尝试过的代码样本编辑你的问题吗。也许吧(帮助欣赏/唠叨/感谢不属于问题)编辑整个问题以澄清。如果我运行var_dum

我的文件中有一个纬度和经度数据,我正试图通过

我试图为
$result60
行添加函数,但它不起作用。我试图传递函数的值,因此它将使用DM方法计算正确的纬度和经度

企图 如何解决此问题?

您可以使用DMS方法将输入字符串分为3组,其中组
$1
$2
$3
可以被调用以返回
$decimal

正则表达式

代码
“当我试图为$result60=..行添加函数时”是什么意思?你能用更详细的信息和你尝试过的代码样本编辑你的问题吗。也许吧(帮助欣赏/唠叨/感谢不属于问题)编辑整个问题以澄清。如果我运行var_dump($matches);我可以看到我的数据中的所有更改(Appx 600),但是如何转换和显示整个页面,以及页面上的所有其他内容?谢谢
$re60 = '/([EW])([0-9][0-9][0-9])([0-9][0-9])/s';
$str60 = 'E16130';
//$subst60 = '\\3\\2\\1';
$subst60 = DMS2Decimal($degr = \\2, $mins = \\3, $secs = 0, $dir = \\1);
$result60 = preg_replace($re60, $subst60, $str60);
echo "The result of the substitution is ".$result60;
/([EWSN])([0-9]{3})([0-9]{2})/s
$str60 = 'E16130';
preg_match_all('/([EWSN])([0-9]{3})([0-9]{2})/s', $str60, $matches);
$result60 = DMS2Decimal($degrees = (int) $matches[2][0], $minutes = (int) $matches[3][0], $seconds = 10, $direction = strtolower($matches[1][0]));

echo "The result of the substitution:  y: " . $result60;

function DMS2Decimal($degrees = 0, $minutes = 0, $seconds = 0, $direction = 'n')
{
    //converts DMS coordinates to decimal
    //returns false on bad inputs, decimal on success

    //direction must be n, s, e or w, case-insensitive
    $d = strtolower($direction);
    $ok = array('n', 's', 'e', 'w');

    //degrees must be integer between 0 and 180
    if (!is_numeric($degrees) || $degrees < 0 || $degrees > 180) {
        $decimal = false;
    }
    //minutes must be integer or float between 0 and 59
    elseif (!is_numeric($minutes) || $minutes < 0 || $minutes > 59) {
        $decimal = false;
    }
    //seconds must be integer or float between 0 and 59
    elseif (!is_numeric($seconds) || $seconds < 0 || $seconds > 59) {
        $decimal = false;
    } elseif (!in_array($d, $ok)) {
        $decimal = false;
    } else {
        //inputs clean, calculate
        $decimal = $degrees + ($minutes / 60) + ($seconds / 3600);

        //reverse for south or west coordinates; north is assumed
        if ($d == 's' || $d == 'w') {
            $decimal *= -1;
        }
    }

    return $decimal;
}
The result of the substitution:  y: 161.5027777777