SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot sappo's Avatar
    Join Date
    Sep 2005
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whats the problem with: if (empty($_REQUEST)) {

    Basically all I want to do is run something when there's nothing in the search string.

    I use - if (isset($_REQUEST['foo'])) { - quite a bit so I thought - if (empty($_REQUEST)) { - might work.

    Does anyone know how to do this?

    Cheers all,
    Check out my Movie Trailers website - Popcorn Trailers

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    do: print_r($_REQUEST)

    You'll see why that doesn't work. Is that page expecting POST and GET requests? If not, just check for the absence them instead of REQUEST.

  3. #3
    SitePoint Zealot sappo's Avatar
    Join Date
    Sep 2005
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome cheers,
    Check out my Movie Trailers website - Popcorn Trailers

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Not taking anything away from Stymiee but take a read of this, double negatives can be a real headache to debug.
    isset() empty() is null and all the stuff

    I am not saying learn it, just bookmark it in case one evening you feel you are losing your sanity in some if() clause. Happens.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Not taking anything away from Stymiee but take a read of this, double negatives can be a real headache to debug.
    isset() empty() is null and all the stuff

    I am not saying learn it, just bookmark it in case one evening you feel you are losing your sanity in some if() clause. Happens.
    That's a helpful chart.

    It's really easy to miss the difference between "" and " ", but it is definitely there and something you need to be aware of when debugging.


  6. #6
    SitePoint Addict pkSML's Avatar
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sappo View Post
    Basically all I want to do is run something when there's nothing in the search string.

    I use - if (isset($_REQUEST['foo'])) { - quite a bit so I thought - if (empty($_REQUEST)) { - might work.

    Does anyone know how to do this?

    Cheers all,
    Simple!
    PHP Code:
    if (strlen($_REQUEST['foo']) < 1) {echo "String's empty";} 
    I use this syntax all the time.

    BTW, thanks to Cups for the link to http://www.deformedweb.co.uk/php_variable_tests.php
    -Stephen

    Get a LitlURL to this page!


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
  •