Check if a variable is empty

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-04-17T20:07:11Z Indexed on 2010/04/17 20:13 UTC
Read the original article Hit count: 220

Filed under:
|
|

I have some user-submitted variables that I want to display in a different part of my site like this:

<div class="pre_box">Term: </div>
<div class="entry"><?php $key='term'; echo get_post_meta($post->ID, $key, true); ?></div>

Occasionally, these variables might be empty in which case I don't want to display the label for the empty variable. In the example above I would want to hide the <div class="pre_box">Term: </div> part. Is there some simple way to check if a php variable like the one above is empty and prevent the label from being displayed?

© Stack Overflow or respective owner

Related posts about php

Related posts about html