我升级到 PHP 5.3 并收到错误:ereg 已被弃用。
我可以用什么来代替这个??
function CheckIfAlphaNumberic($text) {
if (ereg('[^A-Za-z0-9]', $text)) {
unset ($text);
}
return $text;
}
您可以使用preg_match()
:
function CheckIfAlphaNumberic($text){
if (preg_match('#[^A-Za-z0-9]#', $text)) {
unset ($text);
}
return $text;
}
另请参阅:从 ereg 切换到 preg
此外,您可以使用return null;
而不是unset ($text);
采用preg_match