PHP preg_match 查找字段值
PHP preg_match find field value
这是我的示例代码:
$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
)
这是我的示例代码:
$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
)