Sunday, 27 November 2011

Getting an average number using PHP

<?
$total_ratings 
= (3+2+3+1+5+2+3);$total_votes 7;$average $total_ratings $total_votes;
print(
"The Average Rating Is: $average");?>

Setting and retrieving a cookie

<?
$check 
"test";$check .= $filename;
if (
$test == $check)
{
print(
"<HTML><BODY>You have already voted. Thank you.</BODY></HTML>");
}
else
{
$rated "test";$rated .= $filename;setcookie(test$ratedtime()+86400);
print(
"<HTML><BODY><br>You haven't voted before so I recorded your vote</BODY></HTML>");
}
?>

Add date time stamp "page last updated on..." using filemtime function using forms, cookies, flat file databases, random number generation

<html>
<head>
<title>Page last updated on month/date/year hour:min PHP Script</title>
</head>
<?
$last_modified 
filemtime("example7.php3");
print(
"Last Modified ");
print(
date("m/j/y h:i"$last_modified));?></body>
</html>

Change background color based on day of the week using array

<html>
<head>
<title>Background Colors change based on the day of the week</title>
</head>
<?
$today 
date("w");$bgcolor = array("#FEF0C5""#FFFFFF""#FBFFC4""#FFE0DD","#E6EDFF""#E9FFE6""#F0F4F1");?><body bgcolor="<?print("$bgcolor[$today]");?>">
<br>This just changes the color of the screen based on the day of the week
</body>
</html>

Change background color based on day of the week using if else elseif statements

<html>
<head>
<title>Background Colors change based on the day of the week</title>
</head>
<?
$today 
date("l");
print(
"$today");
if(
$today == "Sunday")
{
$bgcolor "#FEF0C5";
}
elseif(
$today == "Monday")
{
$bgcolor "#FFFFFF";
}
elseif(
$today == "Tuesday")
{
$bgcolor "#FBFFC4";
}
elseif(
$today == "Wednesday")
{
$bgcolor "#FFE0DD";
}
elseif(
$today == "Thursday")
{
$bgcolor "#E6EDFF";
}
elseif(
$today == "Friday")
{
$bgcolor "#E9FFE6";
}
else
{
// Since it is not any of the days above it must be Saturday$bgcolor "#F0F4F1";
}
print(
"<body bgcolor=\"$bgcolor\">\n"); ?><br>This just changes the color of the screen based on the day of the week
</body>
</html>

Current month/day/date with HTML colors & formatting

<html>

<head>
<title>PHP Script examples!</title>
</head>
<font face="Arial" color="#FF00FF"><strong><? print(Date("m/j/y")); ?></strong></font>

<body>
</body>
</html>

Current month/day/date format

<html>

<head>
<title>Example #3 TDavid's Very First PHP Script ever!</title>
</head>
<? print(Date("m/j/y")); ?>
<body>
</body>
</html>