PHP - 如果变量不为空,请回显一些html代码 [英] PHP - If variable is not empty, echo some html code

查看:196
本文介绍了PHP - 如果变量不为空,请回显一些html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一些html代码,如果一个变量不是空的,否则我想不显示任何内容。

I would like to display some html code if a variable is not empty, else I would like to display nothing.

我试过这段代码,但没有'

I've tried this code but doesn't work:

<?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代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆