Tech Musings

Sunday, August 12, 2007

PNG transparency problems in Internet Explorer

UPDATE 1/11/07! I recently switched out code produced by Dreamweaver's rollover behavior to the rollover code Bob Olsa made available in the source code on this page: http://homepage.ntlworld.com/bobosola/png_mouseover.htm


I'm actually quite proud of myself! I managed to fix a problem that's been bugging me for quite some time. Due to a quirk in the way Internet Explorer 5.5 and 6 on Windows handles PNG alpha transparency (or, more accurately stated, DOESN'T handle it), my navigation buttons on my photography details page were not displaying properly in IE after I applied a javascript rollover effect using a standard Dreamweaver swap image behavior. My swapped png images which include transparent elements did not work and showed as all gray (grey) in the IE 6 browser environment.

After some research I discovered a nice javascript-based fix for IE's PNG transparency problem using Bob Osola's alphaimageloader script, but the script requires that height and width attributes of transparent PNG images be clearly defined on the page or the script won't fix the png transparency problem. Dreamweaver's canned javascript for rollover buttons DOES NOT define the width and height of the target swapped image, so the alpatransparency PNG fix was not working with my transparent buttons. And, to top it off, the generated script from the DW behavior was so incredibly complex that I had no idea where to add these additional height and width attributes.

I posted my problem in the webdeveloper forums asking for guidance. A helpful gent told me where the width and height should be inserted in the bloated Dreamweaver code, and after tinkering with it a bit I finally arrived at the fix as posted in the aforementioned webdeveloper thread here.

Wednesday, August 01, 2007

PHP elseif statements

This has gotten me more than once. It seems like I always get one of these

Parse error: parse error, unexpected T_ELSEIF in mypath/to/the_page.php on line 534

when I craft my else if statements. Undoubtedly, it's because I surround each else if statement within its own set of PHP <? ?> delimiters.

For example, this code will throw the error:

<? $time = date("H:i:s"); ?>
<? if ($time >= "01:00:00" && $time <= "11:59:59") { echo "Good Morning, "; } ?>
<? elseif ($time >= "12:00:00" && $time <= "18:29:59") { echo "Good Afternoon, "; } ?>
<? elseif ($time >= "18:30:00" && $time <= "24:00:00") { echo "Good Evening, "; } ?>
<? else { echo "Hi, "; } ?>
<? echo $row_login['people_firstname']; ?>

whereas the following syntax is correct:

<? $time = date("H:i:s"); ?>
<?
if ($time >= "01:00:00" && $time <= "11:59:59") { echo "Good Morning, "; }
elseif ($time >= "12:00:00" && $time <= "18:29:59") { echo "Good Afternoon, "; }
elseif ($time >= "18:30:00" && $time <= "24:00:00") { echo "Good Evening, "; }
else { echo "Hi, "; }
?>
<? echo $row_login['people_firstname']; ?>

The elseif statement differs from nested if statements that should be contained within the their own curly braces!