3 回答

TA貢獻1909條經驗 獲得超7個贊
我認為 ju 應該使用 strpos ( string $haystack , mix $needle [, int $offset = 0 ] ) 。
就像 if(strpos("email = [email protected]",'=' ) === false ) { 不執行任何操作 } else { 執行某些操作 }

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']

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
}
- 3 回答
- 0 關注
- 139 瀏覽
添加回答
舉報