第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

正則表達(dá)式,用于匹配緯度和經(jīng)度函數(shù)

正則表達(dá)式,用于匹配緯度和經(jīng)度函數(shù)

PHP
梵蒂岡之花 2021-04-27 13:50:33
我的文件上有緯度和經(jīng)度數(shù)據(jù),我正在嘗試通過(guò)convertor函數(shù)調(diào)用該數(shù)據(jù)。我試圖為該$result60行添加功能,但它不起作用。我正在嘗試傳遞該函數(shù)的值,因此它將使用DM方法計(jì)算正確的緯度和經(jīng)度。試圖$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;我該如何解決這個(gè)問(wèn)題?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

您可以使用此RegEx將輸入字符串分成3個(gè)組,其中g(shù)roup為組$1,$2并且$3可以由DMS方法調(diào)用return $decimal。

正則表達(dá)式

/([EWSN])([0-9]{3})([0-9]{2})/s

http://img1.sycdn.imooc.com//609504de0001966a05320208.jpg

代碼

$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


查看完整回答
反對(duì) 回復(fù) 2021-05-07
  • 1 回答
  • 0 關(guān)注
  • 211 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)