$grep=preg_grep("/^(\d+)?\.\d+$/", "11.11");
print_r($grep);
这不应该打印一个由“11.11”组成的数组吗?
答案 0 :(得分:3)
否......您想使用preg_match
... preg_grep
is for arrays:
if(preg_match("/^(\d+)?\.\d+$/", "11.11", $matches)) {
print_r($matches);
} else {
echo "No Match!";
}