Posts Tagged ‘PHP Scripts’

PHP Even or Odd | PHP Tutorial | PHP Script

Thursday, November 12th, 2009

Here is a great way of determining if a value is even or odd, often times I use this function to color a table of data on every other line old school like the green and white line feed paper of my youth.

if( $i&1 ){ even } else{ odd }
or in a fun one liner like i’ve used it many times

$screen_file .= ( $i&1 ? “\t

\n\t
\n” : “\t

\n\t
\n” );

PNG Transparency, IE PNG Transparency

Thursday, July 30th, 2009

This is a simple script to properly render png images in IE and standards compliant browsers. It works differently than the other png programs I’ve found out there.

Typically you use a php session and have php find and replace the png images with the extra garbage that IE needs to render transparency, it works but not that well especially when talking about background-image png’s. I’ve taken a different approach. Rather than buffering the page in a session and having the server work hard to swap everything and render the page I’ve gone with an in-line approach.

First include the file png-img.php before the head of your document, oh you have to have .htaccess override enabled so you can include php in your .html files otherwise you have to go with .php files so this php script will run.

Second when coding an image into your page; rather than the traditional <img> tag, we are going to use a php echo instead. <?php echo png_img(‘img or bkg’,’/path/to/file.png’,’width’,’height’,’border’,’IE style’,’style all browsers’,’id’,’align’);?>  so when the page is rendered it will detect the browser and write the appropriate <img> tag dependent upon the useragent of the browser. The nice thing is you can specify a different style for IE than the other browsers, also you can use it for bkg png’s, by default they are scaled, however with a simple php str_replace you can set that to whatever you want. Also since it’s simple php with html it’s easy to update with any feature you would want to add later.

PNG Image [PHP Script]

Theme Forest Turned Me Down

Thursday, July 30th, 2009

Apparently themeforest.com doesn’t want to sell my png image program… oh well, so I’m providing it to anyone that would like it here on my blog. My next post will have it attached with some instructions for use.