Show an Image if a PHP argument proves true
I barely know how to use PHP and I can't seem to make my code show an image if a condition proves true. This is the code:
<?php
$search=get_search_query();
$first=$search[0];
if ($first=="#"){
}
?>
I tried writing this thinking it would work and it didn't:
echo "<html>";
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg'>";
Also I tried a code I found which starte开发者_StackOverflow社区d with the function: header()
but it caused a tremendously long error, which said something like header already defined.
Thanks
You have used 'double quotes' incorrectly in the echo statement.
Try the following:
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg' alt='Preview not available' />"
Regards, Mahendra Liya.
You should var_dump($first)
to know what it contains
check if the condition is really getting true
and also put single quote inside the double quote.
if ($first=="#"){
echo 'yes it is true';
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg'>";
}
close the img
tag
The part of the query string starting with #
(so-called "hash") is not being sent to the server. That is, if your page is called like myblog.com/foo?bar=baz#quux
, you php script will only receive myblog.com/foo?bar=baz
. You need javascript if you want to handle urls with hashes.
精彩评论