WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Quote For the Day
Categories : PHP, Utilities, Filesystem Click here to Update Your Picture
Joyce Babu
Date : Jul 01st 2006
Grade : 3 of 5 (graded 4 times)
Viewed : 10828
File : 4436.zip
Images : No Images for this code example.
Search : More code by Joyce Babu
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

This script can be used for displaying a randomly selected quote from a given list of quotes. The quote changes every day. New quotes can be added.

See the quotes-example.php for a working example of the script. Make sure you chmod 777 quotes.txt.


quotes.php
<?php
/*
Function
* To display a randomly selected Quote for the day
How to use
* Create a file called 'quotes.txt' and chmod it 777
* Include the file [Eg: include 'quotes.php';]
* call the function showQuote where you want to show the quote [Eg: showQuote();]

*/

/*
* To add more insert
   $quote[] = "Quote --Name"
*/
$quotes[] ="The value of a man resides in what he gives and not in what he is capable receiving. --Albert Einstein";
$quotes[] ="To cease smoking is the easiest thing I ever did. I ought to know, I've done it a thousand times.--Mark Twain";
$quotes[] ="Let us be thankful for the fools. But for them the rest of us could not succeed.--Mark Twain";
$quotes[] ="Suppose you were an idiot... And suppose you were a member of Congress... But I repeat myself.--Mark Twain";
$quotes[] ="There are several good protections against temptation, but the surest is cowardice.--Mark Twain";
$quotes[] ="The monotony and solitude of a quiet life stimulates the creative mind. --Albert Einstein";
$quotes[] ="I love to travel, But hate to arrive --Albert Einstein";
$quotes[] ="Do you believe in immortality? No, and one life is enough for me --Albert Einstein";

$file = "quotes.txt";

function
showQuote(){
global
$file,$quotes;
    if(
file_exists($file)){
       
$entry = file($file);
       
$entry = split("\|",$entry[0]);
    }
   
// Check the files have been updated today. If not update it
   
if($entry[0] != date('j')){
       
$idx = _newQuote();
    }else{
       
$idx = $entry[1];
    }
   
$quote = split('--',$quotes[$idx]);
    echo
"<div class='quote'>$quote[0]<span class='author'>$quote[1]</span></div>";
}
function
_newQuote(){
    global
$file, $quotes;
   
$randomid = mt_rand(0,count($quotes)-1);
   
$content = date('j') . "|$randomid";
   
// If $file doesnot exist attempt to create
   
if(!file_exists($file)) touch($file);
   
// Check whether the file is writable or not
   
if (is_writable($file)){
        if (!
$handle = @fopen($file, 'w'))echo "<b>Error</b>: Could not open the file<br>";
        elseif (@
fwrite($handle, $content) === FALSE)echo "<b>Error</b>: Could not write to the file<br>";
        else{
           
fclose($handle);
            return
$randomid;
        }
    }else echo
"<b>Error</b>: $file is not writable<br>";
}
?>



Usage Example
<?php
/*

This is an example on how to use the code.
Make sure that you have made the file quote.txt writable (777)

*/


/* Add this at the top of the page. */
include 'quotes.php';
?>
<!doctype html public "-//w3c//dtd html 4.1 transitional//en">
<html>
<head>
<title>Thought For The Day</title>
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta name="MSSmarttagsPreventParsing" content="TRUE" />
<meta name="robots" content="index,follow" />
<script type="text/javascript" language="JavaScript">
<!--
if (top.location != location)top.location.href = document.location.href;
//--></script>
<style>
body, table{font:normal 12px Verdana, Arial, sans-serif;}
.quote{font:bold 12px Arial;}
.quote .author{font-weight:normal;font-style:italic;display:block;float:right;}
</style>
</head>

<body bgcolor="#ffffff">
<table style="height:100%;width:100%;">
<tr><td>

<center><table cellspacing="2" cellpadding="0" style="">
<tr><td style="background:#F4F4F9;border:1px #C0C0C0 solid;">
<table style="width:100%;">
<tr><td style="text-align:left;"><b>Today's Thought</b></td><td style="text-align:right;"> <?php echo date('j<\s\u\p>S</\s\u\p> M, Y'); ?> </td></tr></table>
</td></tr>
<tr><td style="background:#F4F4F9;border:1px #C0C0C0 solid;padding:15px 10px;">
<?php
/* Add this where you want the quote to appear */
showQuote();
?>
</td></tr></table>
</center>
</td></tr></table>
</body>
</html>



grab directory listings into an array the example prints out each subdirectory in the main dir - further work is to be performed on this one
Categories : Filesystem, PHP, Directories, Search, Utilities
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
Contents Page - a script to build contents pages.
Categories : Complete Programs, PHP, Utilities, Filesystem
Single-file PHP news system with automatic folder structure creation
Categories : PHP, Filesystem, Arrays
PHPBrowser - browsing linux file systems.
Categories : PHP, Linux, Filesystem
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
This program implements hot link prevention in php. It is useful for webmasters who do not have access to the server at a level where they can control hot linking can still supply some type of hot link prevention for thier site by using php.
Categories : PHP, Filesystem, Graphics, Content Management
Get the correct extension and MIME types of an image, even when the filename is incorrect.
Categories : PHP, Filesystem, General SQL
Keep() - maintenance function for backup folders
Categories : PHP, Filesystem, Maintenance
windows nt php/3 file upload script
Categories : Filesystem, PHP, IIS, WinNT, Web Servers
Directory Viewer, Directory Content Viewer, Directory Structure to HTML. This code will basically create a complete set of HTMLs to let a user navigate through any directory you want. Excellent code for large file sharing pages.
Categories : Directories, Filesystem, PHP
JSON File Upload
Categories : PHP, AJAX, Filesystem
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Working with files - return an array of files within a directory
Categories : PHP, Strings, Variables, Filesystem
Take multiple text files and do simple formatting on them and add them to a webpage
Categories : HTML, Filesystem, PHP