PHP:如果为空&空的 [英] PHP: if !empty & empty

查看:52
本文介绍了PHP:如果为空&空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个表格.有2个字段.如果您已填写YouTube,我想做的"Youtube"和链接"应该这样做:

So i have this form.. With 2 fields. "Youtube" and "link" I want to do if you have filled in YouTube, it should do this:

if(!empty($youtube)) {
 if ($pos === false) { 
 echo "Du skal indtaste youtube et URL, som starter med 'http://www.youtube.com/watch?..<br>";
 echo "<br> Har du ikke din video på YouTube, skal du ikke udfylde feltet, men kun 'Link' feltet.<br><br>";
 echo "<a href='javascript:history.back();'>Gå tilbage</a>";
 }

}

这可以完成它的工作,但是我也想检查相同的if(),如果链接中没有任何内容.我这样做很简单:

This do its job, but i also want to check on the same if(), if nothing in link. So ive did this:

    if(!empty($youtube) && empty($link)) {
     if ($pos === false) { 
     echo "Du skal indtaste youtube et URL, som starter med 'http://www.youtube.com/watch?..<br>";
     echo "<br> Har du ikke din video på YouTube, skal du ikke udfylde feltet, men kun 'Link' feltet.<br><br>";
     echo "<a href='javascript:history.back();'>Gå tilbage</a>";
     }
}

但是,如果我要检查相反的内容,如果LINK中有内容,而youtube中没有任何内容,该怎么办?如果我想检查一下这两个中是否没有东西?

But what if i want to check the opposite, if theres something in LINK and nothing in youtube? And if i want to check if theres nothing at all in those two?

推荐答案

if(!empty($youtube) && empty($link)) {

}
else if(empty($youtube) && !empty($link)) {

}
else if(empty($youtube) && empty($link)) {
}

这篇关于PHP:如果为空&amp;空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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