我想在双引号之间使用字符串,但是要用更具体的术语。 例如,我有一个像这样的字符串:
column_first = "1", column_second = "2"
我要匹配“ 1”和“ 2”,然后将其存储在如下数组中:
Array
(
[0] => 1
[1] => 2
)
我使用正则表达式,然后使用循环来获取所需的结果。还有其他比这更好或更简单的解决方案吗?
<?php
$condition = 'column_first = "1", column_second = "2"';
preg_match_all('/(?<=")(.*?)(?=")/i',$condition,$cond_arr);
$cond_arr_new = array();
foreach($cond_arr[0] as $key => $val){
if($key%2 == 0){
$val = trim($val);
array_push($cond_arr_new, $val);
}
}
print_r($cond_arr_new);