如何在PHP中使用IF语句来决定是否显示图像?
我正在使用wunderground.com API设置天气页面。无论如何,我想做以下工作: 如果变量如何在PHP中使用IF语句来决定是否显示图像?,php,html,image,Php,Html,Image,我正在使用wunderground.com API设置天气页面。无论如何,我想做以下工作: 如果变量$weather等于Clear,我想显示一个图像 我试过这个: if ($weather=="Clear") echo <img src="http://example.org/clear.gif" alt="Clear"/> if($weather==“Clear”)回波 我需要做什么呢?试试这个 if ($weather=="Clear") echo '<img src
$weather
等于Clear
,我想显示一个图像
我试过这个:
if ($weather=="Clear") echo <img src="http://example.org/clear.gif" alt="Clear"/>
if($weather==“Clear”)回波
我需要做什么呢?试试这个
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
如果($weather==“Clear”)回波为“”;
如果($weather==“Clear”)
回声“;
echo';
或
echo”“;
您尝试的代码将呈现错误。您需要将HTML文本和任何字符串放在引号内,然后才能echo
它们
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>'
if($weather==“Clear”)回波“”
剩下的,没有什么可以改进的了:)if($weather==“Clear”)echo”“;
或
if ($weather==="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
如果($weather==“Clear”)回波为“”;
或
if($weather==“Clear”)echo用于有条件地呈现html,我通常只使用php标记
if($weather === "Clear") {?>
<img src="http://example.org/clear.gif" alt="Clear"/>
<?php}
if($weather==“Clear”){?>
@科尔约翰逊,对不起。我不明白你的意思。你的答案上有一个-1,现在它不见了。它过去是+1/-1
,而不是+1/0
。@科尔约翰逊,哦,可能有人不喜欢我的答案。请在回答这个答案时付出一些努力。为什么这个解决方案会奏效,OP犯了什么错误。提到这一点会让你的答案充满希望这是一个真正的问题。是的,它缺乏一些基本的想法和研究,但不值得投反对票。+1来自我社区发生了什么事?没有人在回答答案时付出任何努力。答案不是以“试试这个…”的形式。这些是评论。
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>'
if ($weather=="Clear") echo "<img src=\"http://example.org/clear.gif\" alt=\"Clear\"/>";
if ($weather==="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
if ($weather==="Clear") echo <<<ABC
<img src="http://example.org/clear.gif" alt="Clear"/>
ABC;
if($weather === "Clear") {?>
<img src="http://example.org/clear.gif" alt="Clear"/>
<?php}