I am new to php but I have read all the stuff on if, elseif, nested functions and found a few errors in my code (and resolved them) but there is one that I just can’t fathom and I hope someone can tell me what I have done wrong.
I have a php IF function that goes out to a third party website and determines if a specified image file exists; if first file is not found then the ELSEIF determines if a second specified image file exists; if the second specified image is not found either then a simple text message is displayed.
If either the first or the second image file exists then I use the getimagesize() function to extract the width and height of the image and compute new width and height parameters so that the image is displayed, correctly proportioned, on my web page, based on my maximum page-element width.
What is going wrong is that once a specified image is found to exist, the function that is activated, in either the IF or ELSEIF statement, fails to execute correctly. Specifically, the activated function contains two nested <?php . . .> statements and the execution fails at the point of reading the first <?php . . .> statement.
[see below] The activated function fails at <?php echo date('d-M-Y');?> in either instance of an image file being found to exist.
Note: the elements within echo “<h3 align=. . .” display correctly if placed on the webpage independently. It is only when I combine them into the IF, ELSEIF environment that they fail.
Code for analysis:
<?php $url1 = 'http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0711.gif'; $url2 = 'http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0611.gif'; if (fopen($url1, "r")) { echo "Latest Information Typhoon Track 07W <?php echo date('d-M-Y');?>
<p align=\"center\">
<a href=\"http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0711.gif\">
<?php
list($width, $height, $type, $attr)=getimagesize(‘http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0711.gif’);
$ht=$height;
$wd=$width;
$max=480;
if($width > $max){
$diff = $width-$max;
$percnt_reduced = (($diff/$width)100);
$ht = round($height-(($percnt_reduced$height)/100));
$wd= $width-$diff;
}
echo “<img src=”’.‘http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0711.gif’.’" height="’.$ht.’" width="’.$wd.’" alt=“Latest Position of current typhoon 06W Philippines” title=“Latest Typhoon Track Click to see original at JTWC” border=“3” style=“border-color:#FFFFFF” >"; ?>
} elseif (fopen($url2, “r”)) {
echo "<h3 align=\"center\">Latest Information Typhoon Track 06W <?php echo date('d-M-Y'); ?></h3>
<p align=\"center\">
<a href=\"http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0611.gif\">
<?php
list($width, $height, $type, $attr)=getimagesize(‘http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0611.gif’);
$ht=$height;
$wd=$width;
$max=480;
if ($width > $max) {
$diff = $width-$max;
$percnt_reduced = (($diff/$width)100);
$ht = round($height-(($percnt_reduced$height)/100));
$wd= $width-$diff;
}
echo “<img src=”’.‘http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc/warnings/wp0611.gif’.’" height="’.$ht.’" width="’.$wd.’" alt=“Latest Position of current typhoon 06W Philippines” title=“Latest Typhoon Track Click to see original at JTWC” border=“3” style=“border-color:#FFFFFF” >"; ?>
} else {
echo “<h4 align=“center”>There are no current Typhoon Warnings in effect . . . cool”;
}
;
clearstatcache(); ?>