PHP - 如果变量不为空,则回显一些 html 代码

标签 php html variables

如果变量不为空,我想显示一些 html 代码,否则我什么都不显示。

我试过这段代码但不起作用:

<?php 
    $web = the_field('website');
    if (isset($web)) {
?>
       <span class="field-label">Website: </span><a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a> 
<?php
    } else { 
        echo "Niente";
    }
?>

最佳答案

if (!empty($web)) {
?>
    <span class="field-label">Website:  </span><a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a> 
<?php
} else { echo "Niente";}

http://us.php.net/manual/en/function.empty.php

关于PHP - 如果变量不为空,则回显一些 html 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9592855/

相关文章:

php - 将我的 knockoutjs 模型与我的后端 (PHP) 同步

variables - 生成多个样式表以 gulp

php - 使用 Easybook 突出显示代码的最佳方式

php - 运行 PHP 脚本最快的方法是什么

php - 如何获取 mysql 值并将其放入 php 中的音乐播放列表中

javascript - 尝试在 jquery 中为我的对象设置动画时出现问题

html - 链接在 iOS 设备上被忽略

html - 文本和输入高度不正确

PHP:从php文件中获取PHP的变量、函数、常量

string - 如何将变量值放入 M​​ATLAB 中的文本字符串中?