Your Ad Here

   
  Welcome to online books
  PHP Example Scripts
 
displaying the current date in an HTML page

<html>

<head>
<title>
displaying the current date in an HTML page</title>
</head>
<? print(Date("l F d, Y")); ?>

<body>
</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>




add date time stamp "page last updated on..." using filemtime function


<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>



add date time stamp "page last updated on..." using filemtime function

<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>




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, $rated, time()+86400);
print(
"<HTML>
       <BODY>
       <br>You haven't voted before so I recorded your vote
       </BODY>
       </HTML>"
);
}
?>



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");
?>



generating a rand number from 0 to 9

<?
srand
(time());
$random = (rand()%9);
print(
"Random number between 0 and 9 is: $random");
?>


php simple slot machine - multiple rand number generation

<?
function slotnumber()
{
srand(time());
for (
$i=0; $i < 3; $i++)
{
$random = (rand()%3);
$slot[] = $random;
}
print(
"<td width="33%"><center>$slot[0]</td>");
print(
"<td width="33%"><center>$slot[1]</td>");
print(
"<td width="33%"><center>$slot[2]</td>");
if(
$slot[0] == $slot[1] && $slot[0] == $slot[2])
{
print(
"</td></tr>Winner! -- Hit refresh on your browser to play again");
exit;
}
}
?>

<div align="center"><center>

<table border="1" width="50%">
  <tr>
<?
slotnumber
();
?>
</td>
  </tr>
  <tr>
    <td width="100%" colspan="3" bgcolor="#008080">
<form method="POST" action="example13.php3">
<div align="center"><center>
<p><input type="submit" value="Spin!"></p>
      </center></div>
    </form>
    </td>
  </tr>
</table>
</center></div>



random text link advertising using predefined arrays


<?
$random_url
= array("http://www.tdscripts.com/linkorg.html",
                    
"http://www.tdscripts.com/keno.html",
                    
"http://www.tdscripts.com/ezibill.shtml",
                    
"http://www.tdscripts.com/tdforum.shtml",
                    
"http://www.tdscripts.com/picofday.html",
                    
"http://www.tdscripts.com/gutsorglory.html");

$url_title = array("Link Organizer",
                   
"TD Keno",
                   
"eziBill *Free Promotion!",
                   
"TD Forum",
                   
"TD Pic of Day PHP",
                   
"Guts or Glory Poker PHP");
$url_desc = array("- A comprehensive link list organizer",
"- Offer your site visitors an engaging Keno game without the monetary risk",
"- Sell access to and protect your membership area using iBill and our eziBill script",
"- An unthreaded messageboard script to exchange ideas with your site visitors",
"- Run your own picture of the day script from any site anywhere with this handy script",
"- A casino-style card game written entirely in PHP");
srand(time());
$sizeof = count($random_url);
$random = (rand()%$sizeof);
print(
"<center><a href="$random_url[$random]">$url_title[$random]</a> $url_desc[$random]</center>");
?>


forcing the text in a string to be all upper or lowercase

<?
// force all uppercase
print(strtoupper("i bet this will show up as all letters capitalized<br>"));
// force all lowercase
print(strtolower("I BET THIS WILL SHOW UP AS ALL LETTERS IN LOWERCASE<br>"));
// force the first letter of a string to be capitalized
print(ucfirst("i bet this will show the first letter of the string capitalized<br>"));
// force the first letter of each WORD in a string to be capitalized
print(ucwords("i bet this will show the first letter of every word capitalized<br>"));
?>



searching through meta tags for a search engine

<HTML>
<BODY>
<?
$all_meta
= get_meta_tags("010600.php3");
print(
$all_meta["description"]);
print(
"<br>");
print(
$all_meta["keywords"]);
?>
</BODY>
</HTML>


 
 
  Today, there have been 26 visitors (28 hits) on this page!  
 
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free