WoShiNiBaBa WoShiNiBaBa - 1 year ago 62
HTML Question

Add specific text when there's no text in it

This is my code:

<?php if($tagline != "")
echo $tagline;
echo "Welcome to my Site!";

For some reason, when the tagline is empty, it doesn't add the text.

Answer Source

I'd try another approach for the check of the $tagline variable

if (strlen(trim($tagline)) > 0) {
    echo $tagline;
} else {
    echo "Welcome to my Site!";

or something that you would use in a couple of years :) :

echo (strlen(trim($tagline)) > 0) ? $tagline : "Welcome to my Site!";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download