spacepoet Posted January 31, 2011 Share Posted January 31, 2011 Hello: I have this bit of code in the works (which does not work): <?php if ( $mySubHeader; != "" ) { echo " <h2> <?php echo $mySubHeader; ?> </h2> "; } What I am trying to do is to show the H2 tag only if it has a value from the database. Otherwise, I do not want to show it. What is the correct way to do this? Thanks. Link to comment https://forums.phpfreaks.com/topic/226186-not-showing-a-tag-if-the-value-is-empty/ Share on other sites More sharing options...
litebearer Posted January 31, 2011 Share Posted January 31, 2011 Perhaps... if(trim($mySubHeader) != "" ) { echo " <h2>" . $mySubHeader . "</h2>"; }else{ /* do something else */ } Link to comment https://forums.phpfreaks.com/topic/226186-not-showing-a-tag-if-the-value-is-empty/#findComment-1167650 Share on other sites More sharing options...
spacepoet Posted January 31, 2011 Author Share Posted January 31, 2011 Perfect! I did this: <?php if(trim($mySubHeader) != "" ) { echo "<h2>" . $mySubHeader . "</h2>"; } ?> Just what I needed. Thanks much! Link to comment https://forums.phpfreaks.com/topic/226186-not-showing-a-tag-if-the-value-is-empty/#findComment-1167653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.