欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP filter例子

程序员文章站 2022-06-16 16:28:42
...

?php function convertSpace($str) { return str_replace(' ', '_', $str); } $str = 'i am a great guy!'; echo filter_var($str, FILTER_CALLBACK, array('options'='convertSpace')); echo filter_var($str, FILTER_CALLBACK, array('options'='strtouppe

function convertSpace($str) {
return str_replace(' ', '_', $str);
}

$str = 'i am a great guy!';

echo filter_var($str, FILTER_CALLBACK, array('options'=>'convertSpace'));
echo filter_var($str, FILTER_CALLBACK, array('options'=>'strtoupper'));

//验证email
$email = 'xxx@dabaidu.com';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'email is not valid';
} else {
echo 'email is valid';
}