我总是把我的东西用在跟随线上,但我真的无法理解。
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()
答案 0 :(得分:2)
这:/[^=]*=([^;@]*)/
将所有...=...
内容收集到$ matches数组中。
[^=]
表示除= [^;@]
表示除了以外的任何字符;和@ ()
表示将其明确收集到$ matches $ pcount / $ ncount从显示其比率的值中获得百分比。
答案 1 :(得分:2)
模式细节:
[^=]* # 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