亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從字符串中讀取預定義值 (PHP)

從字符串中讀取預定義值 (PHP)

PHP
月關寶盒 2023-07-07 10:46:32
PHP,我想讀出字符串中的特定值,并返回其值:predefined Values: '=', '>', '<', '>=', '<=';String1 to Search for: "email = [email protected]"         //return =String2 to Search for: "age > 20"                       //return >有人知道獲得這些值的最簡單方法嗎?如果對于數組有更好的解決方案,也請告訴我。
查看完整描述

3 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

我認為 ju 應該使用 strpos ( string $haystack , mix $needle [, int $offset = 0 ] ) 。

就像 if(strpos("email = [email protected]",'=' ) === false ) { 不執行任何操作 } else { 執行某些操作 }


查看完整回答
反對 回復 2023-07-07
?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

你可以使用正則表達式


if(preg_match('^(?<left>\w+?) (?<operator>[=><]=?) (?<right>\w+?)$', $string, $matches)) {

    var_dump($matches)

}


//will output

Array

(

    [0] => email = [email protected]

    [left] => email

    [1] => email

    [operator] => =

    [2] => =

    [right] => [email protected]

    [3] => [email protected]

)

所以你可以簡單地$matches['left']計算方程的左邊部分。$matches['right']對于正確的部分,你的操作員是$matches['operator']


查看完整回答
反對 回復 2023-07-07
?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

我想我找到了解決方案:


$arrayz = str_split($string);

$operatorsarr = array('=', '>', '<', '>=', '<=');

$matches = array_intersect($arrayz, $operatorsarr);


foreach ($matches as $op){

                

        $operator = $op;     //*there is only one operator per String     

}


查看完整回答
反對 回復 2023-07-07
  • 3 回答
  • 0 關注
  • 139 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號