如果php echo内容为空,则隐藏div

时间:2017-06-19 11:46:19

标签: javascript php

<div class="botontour"><a href="<?php echo $currentItem['video'];?
>">Video Tour 3D</a></div>

我想要隐藏整个&#34; botontour&#34; div如果php echo没有返回。

4 个答案:

答案 0 :(得分:1)

在这种情况下,您可以检查它是否为empty

<?php
if (!empty($currentItem['video'])) {
?>
    <div class="botontour"><a href="<?= $currentItem['video'];?>">Video Tour 3D</a></div>
<?php
}
?>

答案 1 :(得分:0)

<?php 
    if(isset($currentItem['video']) && !empty($currentItem['video'])){
    ?>

 <div class="botontour"><a href="<?= $currentItem['video'];?>">Video Tour 3D</a></div>

<?php  } >

答案 2 :(得分:0)

  

empty - 确定变量是否为空

<?php

if(!empty($currentItem['video'])) { ?>

<div class="botontour"><a href="<?php echo $currentItem['video'];
>">Video Tour 3D</a></div>

<?php } ?>

答案 3 :(得分:0)

您可以使用strlen():http://php.net/manual/fr/function.strlen.php

    <?php if(strlen($currentItem['video']) != 0) { ?>
    <div class="botontour"><a href="<?php echo $currentItem['video'];?
     >">Video Tour 3D</a></div>
    <?php } ?>

或清空():http://php.net/manual/fr/function.empty.php

    <?php if(!empty($currentItem['video'])) { ?>
    <div class="botontour"><a href="<?php echo $currentItem['video'];?
     >">Video Tour 3D</a></div>
    <?php } ?>