PHP预匹配查找字段值
这是我的示例代码:PHP预匹配查找字段值,php,regex,preg-match,Php,Regex,Preg Match,这是我的示例代码: $string = "teste aa=11 teste teste"; $var = "aa|bb|cc"; if (preg_match('/^'.$var.'/', $string,$matches)){ echo "field [$matches[0]], value [$matches[1]]"; 输出: field [aa],value [] 我试图输出如下内容: field [aa],value[11] 我尝试了几个不同的正则表达式,但没有
$string = "teste aa=11 teste teste";
$var = "aa|bb|cc";
if (preg_match('/^'.$var.'/', $string,$matches)){
echo "field [$matches[0]], value [$matches[1]]";
输出:
field [aa],value []
我试图输出如下内容:
field [aa],value[11]
我尝试了几个不同的正则表达式,但没有成功。如何使用正则表达式获取aa
的值
我试图在一个字符串中搜索多个字符串,并提取它们的值,以便以后更改
$string = "teste aa=11 teste teste";
$var = "aa|bb|cc";
preg_match('/^.*('.$var.')=(.*?)\s.*/', $string, $matches);
print_r($matches);
产出:
Array
(
[0] => teste aa=11 teste teste
[1] => aa
[2] => 11
)
这段代码做第一个输出请看-有帮助吗?很好!很高兴听到这个消息