1

I'm sure this is fairly simple but I really don't get php is there a way to have the below code to display none if there's no url details entered?

    <div class="details">       
        <h3>web</h3>
        <div>URL: <span><a href="<?=$website_url?>"><?=$website_url?></a></span></div>
    </div>

Thanks

Nsokyi
  • 394
  • 4
  • 21

1 Answers1

0

Wrap it in an if statement.

<? if($website_url): ?>
    <div class="details">       
            <h3>web</h3>
            <div>URL: <span><a href="<?=$website_url?>"><?=$website_url?></a></span></div>
     </div>
<? endif;?>

EDIT

This might be better:

<?php if($website_url){ ?>
        <div class="details">       
                <h3>web</h3>
                <div>URL: <span><a href="<?php echo $website_url; ?>"><?php echo $website_url; ?></a></span></div>
         </div>
<?php } ?>
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
  • -1: in principle, yes, but short tags? The alternate control structure syntax? Neither are deprecated but at best they are contentious. – symcbean May 05 '11 at 12:21
  • He used short tags in his question, I just adapted his code style as I saw it. He is free to adapt it. – Mild Fuzz May 05 '11 at 12:24
  • @symcbean: Actually, there are quite a lot of developers who use alternate control structure syntax when mixing HTML and PHP code like this. – Sander Marechal May 05 '11 at 12:30
  • Wordpress uses alternate control structure syntax. I think it looks a lot nicer when mixing HTML and PHP, easier to read. The following question seems to suggest short tags are not too bad either -> http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use – Mild Fuzz May 05 '11 at 12:37
  • Many thanks Mind Fuzz, (appropriate name as that's what my mind turns into whenever I try to learn PHP) that did the trick. – Nsokyi May 05 '11 at 12:51
  • haha, glad it helped. Be sure to mark the answer as accepted (little tick under the up/down voting) – Mild Fuzz May 05 '11 at 13:14
  • ah, that's what's that is... d'oh! – Nsokyi May 05 '11 at 13:18
  • No probs, I note you're a new member. Learn the ropes and reap the benefits of a great community. – Mild Fuzz May 05 '11 at 13:21