Monday, 10 June 2013

What is the use of filter_var function in PHP


In any web application development you must ensure that data coming from user is valid. To validate the user input data or any variable you can use the function filter_var .

Synatx and example of filter_var  function is given below

filter_var(variable_to_Filetr, type_of_filter, filter_options)



<?php
$var= 44;

if(!filter_var($var, FILTER_VALIDATE_INT))
  {
  echo("Variable is not valid integer");
  }
else
  {
  echo("variable is Integer");
  }
?>

In above code you will find that we are validating the variable to check if it is integer or not.


No comments:

Post a Comment