为何匹配不全 求原因 ('/$(w+)=(.+?) $/i', $d, $matches2)

WBOY
Release: 2016-06-23 13:28:37
Original
833 people have browsed it

$d = ‘$Row=10 $cid=1 $table=channel $sql=select * form abc $Where=[FatherID]=0 $’


preg_match_all('/\$(\w+)=(.+?) \$/i', $d, $matches2); 
if($matches2){
$d2 = '';
for($k=0;$k $d2 = $d2 . $matches2[1][$k] . '="' .$matches2[2][$k] .'" ';
}
}
 
结果 只有 Row="10" table="channel" Where="[FatherID]=0"

应该是 Row="10" cid="1"  table="channel"  $sql="select * form abc" Where="[FatherID]=0" 才对呀 错在哪呢?


回复讨论(解决方案)

应该匹配到5个才对呀 为啥只有3个呢 求大神给个解决方案

$d = '$Row=10 $cid=1 $table=channel $sql=select * form abc $Where=[FatherID]=0 $';preg_match_all('/\$(\w+)=([^$]+)/i', $d, $matches2);print_r($matches2);
Copy after login
Array(    [0] => Array        (            [0] => $Row=10             [1] => $cid=1             [2] => $table=channel             [3] => $sql=select * form abc             [4] => $Where=[FatherID]=0         )    [1] => Array        (            [0] => Row            [1] => cid            [2] => table            [3] => sql            [4] => Where        )    [2] => Array        (            [0] => 10             [1] => 1             [2] => channel             [3] => select * form abc             [4] => [FatherID]=0         ))
Copy after login

你 /\$(\w+)=(.+?) \$/ 这样写不行的原因是
$Row=10 $cid=1  $table=channel $sql=select * form abc  $Where=[FatherID]=0 $
看明白了吗?

用这个规则,你还需要 $d = str_replace('$', '$$', $d), 

你 /\$(\w+)=(.+?) \$/ 这样写不行的原因是
$Row=10 $cid=1  $table=channel $sql=select * form abc  $Where=[FatherID]=0 $
看明白了吗?

用这个规则,你还需要 $d = str_replace('$', '$$', $d), 



啊 这么笨的正则啊。。。郁闷 嗯 我改进下 谢啦

你 /\$(\w+)=(.+?) \$/ 这样写不行的原因是
$Row=10 $cid=1  $table=channel $sql=select * form abc  $Where=[FatherID]=0 $
看明白了吗?

用这个规则,你还需要 $d = str_replace('$', '$$', $d), 



啊 这么笨的正则啊。。。郁闷 嗯 我改进下 谢啦
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template