PHP BY EXAMPLE
quote generator
slideshow generator
photo gallery generator
photo paginator gallery generator
address book
basic blog
paypal generator
sc simple cms

qg QG : QUOTE GENERATOR



Example

I agree that there is a natural aristocracy among men
The grounds of this are virtue and talents.
..................................... Thomas Jefferson

PHP Code

//////////////////////////////////////////////////////
//
// This is a VERY simple PHP Random Quote generator.
//
//

$bgcolor = "#FFFFCC";
$textcolor = "black";
$textsize = "2";

// Array Structure:  "Quote","Author"

$allqts = array
    ("The Black Knight Always Triumphs!", 
        "Monty Python",
    "I swear by my life and love of it that I will never live for the sake of
another man, nor ask another man to live for mine" , "Atlas Shrugged", "It is clear that the individual who persecutes a man, his brother,
because he is not of the same opinion, is a monster", "Voltaire", "I agree that there is a natural aristocracy among men
The grounds of this are virtue and talents.", "Thomas Jefferson", "Liberty, when it begins to take root, is a plant of rapid growth.", "George Washington", "Never argue with an idiot.
They drag you down to their level
then beat you with experience", "Dilbert", "The Answer is 42. What is the question?", "Hitchikers Guide to the Galaxy", "Anyone who has never made a mistake has never tried anything new", "Albert Einstein", "Progress doesnt come from early risers, progress is made
by lazy men looking for easier ways to do things.", "Lazarus Long (Time Enough for Love by Robert A. Heinlein)", "Throughout history, poverty is the normal condition of man.
Advances which permit this norm to be exceeded - here and there, now and then -
are the work of an extremely small minority, frequently despised,
often condemned, and almost always opposed by all right-thinking people.
Whenever this tiny minority is kept from creating, or (as sometimes happens)
is driven out of a society, the people then slip back into abject poverty.

This is known as bad luck.", "Robert Heinlein", "A little learning is a dangerous thing; Drink deep, or taste not the
Pierian spring. There shallow draughts intoxicate the brain,
and drinking largely sobers us again", "Alexander Pope", "The early bird gets the worm, but the second mouse gets the cheese", "Anonymous", "Subjugating the enemys army without fighting is the true pinnacle of excellence", "Sun-tzu, The Art of War", "Work as though you were to live 100 years; pray as if you were to die tomorrow", "Benjamin Franklin", "The world is a stage, but the play is badly cast", "Oscar Wilde", "Truth is generally the best vindication against slander.", "Abraham Lincoln", "...mercy to the guilty is cruelty to the innocent...", "Adam Smith", "...I wish that I may never think the smiles of the great and powerful
a sufficient inducement to turn aside from the straight path
of honesty and the convictions of my own mind", "David Ricardo", "Democracy is the worst form of government except for all the others", "Winston Churchill", "You can only know the highest peaks if you have experianced the lowest valleys", "Richard Nixon", "They dress the wound of my people as though it were not serious.
Peace, peace, they say, when there is no peace.", "Jeremiah 6:14", "It is better to remain silent and be thought a fool
than to open your mouth and remove all doubt.", "Jonathan Swift", "The market system delivers the goods people want,
but those who make it work cannot readily explain why it is so.
The socialst or communist system does not deliver the goods,
but those who operate it can readily explain away its failure.", "F.A. Hayek, Law, Legislation and Liberty, Vol. II", "Never Stop Exploringtm", "The North Face" ); // Gets the Total number of Items in the array // Divides by 2 because there is a Quote followed by an Author $totalqts = (count($allqts)/2); // Subtracted 1 from the total because 0 is not accounted for otherwise $nmbr = (rand(0,($totalqts-1))); $nmbr = $nmbr*2; //$nmbr = 18; $quote = $allqts[$nmbr]; $nmbr = $nmbr+1; $author = $allqts[$nmbr]; $space = "....................................."; echo "
"; echo ""; echo "$quote
"; echo "
"; echo "$space $author"; echo "
"; ?>

PHP Code Explanation

Line 7: Select background color and attach it var bgcolor. Used hex # for color.
Line 8: Select text color and attach it var textcolor. Used hex # for color.
Line 9: Select text size and attach it var textsize.
Line 13-61: Put in var allqts quotes and author separate by column. Example: "Just Do It", "Nike". The program will parse the quotes and authors for you. Make sure it is in array format by example above
Line 66: Gets total quotes generator by diving allqts into 2, then store in var totalqts.
Line 69: Get random quote by using function rnd.
Line 70: Generate quote to be display in var nmbr.
Line 74: Put random quote for author in var author.
Line 76: Increase nmbr by 1 and put random quote for quote in var quote
Line 78-85: Display quote to the browser by using the variables above


Tweet Follow      © 2013 | webcula.com (all rights reserved) | php by example