Check whether a variable is empty – PHP

<?php
 // Example 1
 $string="";
 if(empty($string))
  echo "Empty string";
 else
  echo "Not an empty string"; //Empty string
?>

<?php
 // Example 2
 $strng="Test";
 if(empty($strng))
  echo "Empty string";
 else
  echo "Not an empty string";  //Not an empty string
?>

24 thoughts on “Check whether a variable is empty – PHP”

  1. Hello, I enjoy reading through your article. I wanted to write a little comment to support you.

  2. I have been exploring for a little bit for
    any high-quality articles or blog posts on this kind
    of area . Exploring in Yahoo I at last stumbled upon this website.
    Reading this info So i’m satisfied to exhibit that I have an incredibly excellent uncanny feeling I found out exactly what I needed. I so much for sure will make sure to don?t fail to remember this site and provides it a glance on a constant basis.

  3. Greetings from Ohio! I’m bored at work so I decided to browse your website on my iphone during lunch break. I really like the information you provide here and can’t wait to take a look when I get home.
    I’m shocked at how quick your blog loaded on my phone .. I’m not even using WIFI, just 3G .
    . Anyhow, wonderful blog!

  4. Hey would you mind stating which blog platform you’re working with? I’m going to start
    my own blog in the near future but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something
    unique. P.S My apologies for getting off-topic but I had to ask!

  5. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is fundamental and everything.
    However imagine if you added some great photos or videos to give your posts more, “pop”!
    Your content is excellent but with images and videos, this site could certainly be one of the greatest in its niche.
    Awesome blog!

  6. Its like you read my mind! You appear to know a lot about this, like you wrote
    the book in it or something. I think that you could do with a few
    pics to drive the message home a little bit, but instead of that, this
    is fantastic blog. An excellent read. I’ll definitely be back.

  7. Very nice post. I just stumbled upon your weblog and wished to say that I’ve really enjoyed surfing around your blog posts. In any case I’ll be subscribing to your rss feed and I hope you write
    again soon!

  8. It’s perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I wish to suggest you some interesting things or suggestions. Perhaps you can write next articles referring to this article. I wish to read more things about it!

  9. I just like the helpful information you provide to your articles.
    I will bookmark your blog and check again right here frequently.
    I’m fairly certain I’ll be informed many new stuff proper right here!
    Good luck for the following!

  10. Hi, I think your web site may be having browser compatibility issues.
    When I look at your site in Safari, it looks fine but when opening in Internet Explorer, it’s got some overlapping issues. I merely wanted to give you a quick heads up! Other than that, great website!

  11. An interesting discussion is worth comment. I believe that you should publish
    more on this topic, it may not be a taboo subject
    but typically people do not talk about these subjects. To the next!

    Best wishes!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>