SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP filter_input: how to return NULL when it is empty from the input

    Hi,

    How can I return NULL with `filter_input` when the input is empty?

    PHP Code:
    $title filter_input(INPUT_POST'title');
        
    var_dump($title); 
    it returns,

    PHP Code:
    string '' (length=0
    but I want,

    PHP Code:
    null 
    Thanks.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You can only get NULL as the return value if the $variable is not set or fails to be filtered.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SgtLegend View Post
    You can only get NULL as the return value if the $variable is not set or fails to be filtered.
    got it thank you. I think I have write a function or a couple of extra lines to return null for my case. thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •