SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Filter

filter_var

We can check a variable by using a particular type of filter by using filter_var() function. This function takes the variable and the ID or name of the filter as input and checks the variable. It returns True of False based on the checking output. Here is the syntax.
bool=filter_var(variable, Filter ID,optional );
We will try with an example with book_id as variable
if(filter_var($_GET['book_id'],257)){ // id 257 is for validating integers
echo "Yes true book_id validation passed";
}else{
echo "No false book_id validation failed";
}
You can get list of filter ID here
if(filter_var($_GET['book_id'],FILTER_VALIDATE_INT)){
echo "Yes true $book_id";
}else{
echo "No false $book_id";
}
IN the above code we have not user filter id and in that place we have used filter Name. Now let us try one email validation by using email filter
$email = 'userid@example.com';
if(filter_var($email,FILTER_VALIDATE_EMAIL)){
echo " Yes true,  email  validation passed";
}else{
echo "No false, email  validation failed";
}
We can replace the email filter name with email filter ID ( 274 ) , just change the above line with this
if(filter_var($email,274)){

Be the first to post comment on this article :


Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer