Change language

Outputting PHP Programs | Set 2 (Filters)

|
$num = "123" ; if (! filter_var ( $num , FILTER_VALIDATE_INT)) echo ( "Hello" ); else echo ( " Welcome to GeeksforGeeks " ); ?> Parameters:
  • No output is returned
  • Hello
  • Welcome to GeeksforGeeks
  • error
  • Output:
    Welcome to GeeksforGeeks
    Explanation:filter_var() - Filters one variable with the specified filter.question 2 $var = 300; $int_options = array ( "options" = > array ( "min_range" = > 0, "max_range" = > 256)); if (! filter_var ( $var , FILTER_VALIDATE_INT, $int_options )) echo ( "Hello" ); else echo ( " Welcome to GeeksforGeeks " ); ?> Parameters:
  • No output is returned
  • Hello
  • Welcome to GeeksforGeeks
  • error
  • Output:
    Hello
    Explanation:Since the integer is "300", it is not in the specified range, and the output of the above code will look like "The integer is not valid." Question 3 $string = "Welcomeêê to GeêêeksfoøørGeêêeks" ; $string = filter_var ( $string , FILTER_SANITIZE_EMAIL); echo $string ; ?> Parameters:
  • Welcome to GeêêeksfoøørGeêêeks
  • Welcome to GeeeeksfooorGeeeeks
  • Welcome to GeêeksfoørGeêeks
  • WelcometoGeeksforGeeks
  • Output:
    WelcometoGeeksforGeeks
    Explanation:Sanitize - this is nothing more than removing invalid characters or special characters, so invalid characters such as ê and ø and space will be removed.Question 4 $value = ’GeeksforGeeks’ ; $result = filter_var ( $value , FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); ?> Parameters:
  • FALSE
  • TRUE
  • No Output
  • ERROR
  • Output:
    No Output  Explanation:There is an undocumented filter flag for FILTER_VALIDATE_BOOLEAN. The documentation implies that it will return NULL if the value is not true / false. However, this will not happen unless you give it the FILTER_NULL_ON_FAILURE flag. Therefore, the result will be No Output.Question 5         function  GeeksforGeeks (  $string )   {   return  str_replace  (  "_" ,  "" ,  $string );  }   $string  = " I_am_intern_at_GeeksforGeeks! " ;   echo  filter_var (  $string , FILTER_CALLBACK,  array  (  "options"  = >  "GeeksforGeeks" )); ?> Parameters: 
  • I_am_intern_at_GeeksforGeeks!
  • IaminternatGeeksforGeeks!
  • I’m an intern at GeeksforGeeks!
  • error
  • Output:
     I am intern at GeeksforGeeks!
    Explanation:The above code converts all "_" characters to spaces. Call the filter_var() function with the FILTER_CALLBACK filter and an array containing our function.Question 6 $num = ’123 + abc-xyz *’ ; $num = filter_var ( $num , FILTER_SANITIZE_NUMBER_INT); echo $num?> Parameters:
  • 123 + ABC-XYZ *
  • abcxyz *
  • 123 + -
  • error
  • Exit:
    123 + -
    Explanation:filter_var() - with FILTER_SANITIZE_NUMBER_INT, remove all characters except numbers, + - and if necessary.Question 7 $num = ’123 + -abc *’ ; $res = filter_var ( $num , FILTER_SANITIZE_NUMBER_FLOAT); echo $res?> Parameters:
  • 123 + ABC-XYZ *
  • abcxyz *
  • 123 + -
  • error
  • Exit:
    123 + -
    Explanation:filter_var() - with FILTER_SANITIZE_NUMBER_FLOAT, remove all characters except numbers, + - and if necessary.

    Shop

    Learn programming in R: courses

    $

    Best Python online courses for 2022

    $

    Best laptop for Fortnite

    $

    Best laptop for Excel

    $

    Best laptop for Solidworks

    $

    Best laptop for Roblox

    $

    Best computer for crypto mining

    $

    Best laptop for Sims 4

    $

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers


    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method