Reputation: 127
I'm setting up a weather page using the wunderground.com API. Anyway, I want to do the following:
Of the variable $weather
is equal to Clear
, I want to display an image.
I've tried this:
if ($weather=="Clear") echo <img src="http://example.org/clear.gif" alt="Clear"/>
What do I need to do instead?
Upvotes: 0
Views: 109
Reputation: 30404
For conditionally rendering html, I often just use the php tags...
if($weather === "Clear") {?>
<img src="http://example.org/clear.gif" alt="Clear"/>
<?php}
Upvotes: 0
Reputation: 2587
if ($weather=="Clear") echo "<img src=\"http://example.org/clear.gif\" alt=\"Clear\"/>";
OR
if ($weather==="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
OR
if ($weather==="Clear") echo <<<ABC
<img src="http://example.org/clear.gif" alt="Clear"/>
ABC;
andsoon.
Upvotes: 0
Reputation: 78971
The code you tried will render ERROR. You need to place the HTML text and any string within quotes, before you echo
them.
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>'
Remaining, there is nothing else to improve :)
Upvotes: 2
Reputation: 35572
echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
OR
echo "<img src='http://example.org/clear.gif' alt='Clear' />";
Upvotes: 1
Reputation: 53525
if ($weather==="Clear")
echo "<img src=\"http://example.org/clear.gif\" alt=\"Clear\"/>";
Upvotes: 1
Reputation: 4860
Try this
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
Upvotes: 4