我有以下代码来匹配preg_match
函数,使post变得干净###
foreach ( $_POST as $key => $value) {
if (preg_match("~^['r'n's'w'd /<>:,.?@;-]+$~", $value)) {
echo 'Correct';
} else {
echo 'Incorrect';
}
}
我在PHP中有一个POST数组,其中一些字段可能为空。当我把一些字段留空时,它会给出一个错误,这里说的是不正确的,而不是接受。我希望它们通过preg_match
,即使有些字段是空的
我确实有以下内容作为POST的print_r
,其中一些字段为空
Array {
[email] => mi@mi2.com
[facebook] =>
[twitter] =>
[gplus] => glus
[firstname] => mi2
}
<urregex>|(^$)
试试这个。请参阅演示。
http://regex101.com/r/oO8zI4/1