Php 理解preg_匹配公式
不管怎样,我的东西是按照下面的思路工作的,但我真的不明白Php 理解preg_匹配公式,php,regex,preg-match,Php,Regex,Preg Match,不管怎样,我的东西是按照下面的思路工作的,但我真的不明白 if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Desktop/test/b '$test'"),$matches)) { $x = (int) $matches[1][0]; //optionally cast to int
if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Desktop/test/b '$test'"),$matches))
{
$x = (int) $matches[1][0]; //optionally cast to int
$y = (int) $matches[1][1];
$pcount= round((100*$x)/($x+$y),2);
$ncount= round((100*$y)/($x+$y),2);
}
b
是可执行文件,它给出的结果类似于x=10
和y=20
有人能解释一下if()中的任何内容吗:/[^=]*=([^;@]*)/
将所有…=
内容收集到$matches数组中
表示除=[^=]
表示除以下字符以外的任何字符:;及@[^;@]
表示将其收集到$matches中()
[^=]* # is a negated character class that means "all characters except ="
# * is quantifier that means zero or more times
# note that it seems more logical to replace it with +
# that means 1 or more times
= # literal =
( # open the capturing group 1
[^;@]* # all characters except ";" and "@", zero or more times
# (same notice)
) # close the capturing group 1
什么不清楚?阅读PHP手册页面;阅读Regex tuturial——有很多(在谷歌中输入Regex教程),我发现这些是调查Regex的有用工具,@WayneC:谢谢,伙计!我希望你是在净化
$test
谁知道当有人做坏事时会发生什么