Contact
Web Development Team

resources

helpful hints - PHP



Helpful Hints PHP (originally Personal Home Page, but no longer applies) is a simple yet powerful language designed for creating dynamic web pages. PHP is a widely used general-purpose scripting language that is especially suited for web development and can be embedded directly into HTML pages. It runs on a web server, taking PHP code as its input and creating dynamic web pages as output. PHP is literally used on millions of sites today. Key features include:

The LAMP architecture has become on of the most popular in the web industry today as a way of deploying web applications. PHP is commonly used as the P in this bundle alongside Linux, Apache and MySQL. It is this reason that contributes to the millions and millions of PHP generated web sites today.



PHP Alert Box

echo "<script type='text/javascript'> alert('I am here'); </script>";


Comparing Dates (PHP & MySQL)

Comparing dates consists of obtaining both dates and then putting them in a format to easily apply mathematical logic (e.g. greater then or less then).

$todays_date = date("Y-m-d"); // uses PHP date function and displays something like: 2008-10-23

$row['date_exp']; // MySQL database query variable in the form of: 2009-08-25

Now if we convert both of these to time strings using PHP strtotime() function we can compare them.

if ((strtotime($row['date_exp'])) > (strtotime($today_time)) {
     echo 'I have not expired!';
}
else {
     echo 'I have expired!';
}


PHP sttotime() function converts a date to a Unix Timestamp (number of seconds since January 1 1970 00:00:00 GMT)... so, we can compare total number of seconds to total number of seconds!


Force image to not be Cached

Important if you are using dynamic images (i.e. pulling from database)

<img src="../fabric_images/<?=stripslashes($row[some_image]);?>?<?PHP echo time(); ?>"

The little <?PHP echo time(); ?> does the trick!
Copyright © 2008 by DSD Web Works - All rights reserved.
Site Map