RanTex
PHP Random Text script

PLEASE NOTE: I cannot provide free installation support for this free script! Please contact me ONLY about possible bug reports, suggestions or comments! Thank you!

INDEX

COPYRIGHT NOTICE

Copyright 2009 Klemen Stirn. All Rights Reserved.

This script may be used and modified free of charge by anyone AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT. By using this code you agree to indemnify Klemen Stirn from any liability that might arise from it's use.

Using this script requires attribution. In other words: if you are using this script you are required to place a link to PHPJunkyard on your website. You will find some link suggestions here.

Selling the code for this program, in part or full, without prior written consent is expressly forbidden.

Obtain permission before redistributing this software over the Internet or in any other medium. In all cases copyright and header must remain intact. This Copyright is in full effect in any country that has International Trade Agreements with the United States of America or with the European Union.

DESCRIPTION

RanTex is a simple PHP Random Text/Quotes script. Use it to display Random Text or Quotes from a file of your choice on your web pages. RanTex can also display random blocks of HTML code.

REQUIREMENTS

» Installation

Please take 5 minutes time and read installation instructions carefully and completely! This will ensure a proper and easy installation.

If you have problems/questions see the "Troubleshooting and HELP" section further down.

-> Quick install

  1. FTP to the public folder of your server (where the rest of your website is; usually called "public_html", "www" or "site") and create a folder where you will install RanTex (for example named "rantex").
    Example: /public_html/rantex
    Corresponding URL: http://www.yourdomain.com/rantex

    TIP: If you don't know how to FTP files read my simple FTP tutorial

  2. Upload all RanTex files to your server. They should be transferred in ASCII mode.

That's it. To test if RanTex works fine on your server open rantex/test.php in your browser, for example:
http://www.yourdomain.com/rantex/test.php

Your browser should show a sample page with 2 random quotes displayed. Try refreshing the page to see images change.

Got an error message? A few solutions can be found below under HELP and Troubleshooting.

-> Using Random Text script

Now that the script is up and running it's time to choose the text/quotes that should be randomly displayed. You can do so by adding them one per line inside the quotes.txt file. Make sure you don't leave any empty lines between different quotes!

Alternatively you can enter a list of text/quotes inside rantex.php file directly. This is useful if you have large chunks of text that don't fit in one line only. To learn how to this read further down under "Modifying default settings".

To display Random Text/Quote on your website using the default settings paste this code into your web page where you want the text to appear (not sure how?):

<script type="text/javascript" src="http://yourdomain.com/rantex/rantex.php"></script>

If you are using RanTex in a PHP file you can include the text directly (without using Javascript) like this:

<?php $_GET['type'] = 0; include 'rantex.php'; ?>

As simple as that!

Important! Using this script requires attribution. In other words: if you are using this script you are required to place a link to PHPJunkyard on your website. This is all I require in exchange for this free script, please support my work by placing a link on your website. You will find some link suggestions here.

-> Modifying default settings

To modify default settings open rantex.php in a plain text editor (like Notepad or Wordpad on Windows, DO NOT use Microsoft Word!) and scroll down to where it says SETTINGS. Available settings are:

    Variable Description/Setup
    $settings['text_from_file'] Name (path) of the file where random text/quotes are located. Text should be listed one per line. You can use any HTML code you wish inside the text.
    $settings['quotes'] If you prefer not to choose text from a file you can hard code the text/quotes to choose from in this variable.

    To use the hard-coded quotes you need to set above variable to $settings['text_from_file'] = '';

    All quotes must start and end with a single quote ( ' ) and be separated with a comma ( , ). Text can stretch over multiple lines. Any single quotes inside the text must be escaped with a backslash ( \ ). In other words: replace any ' with \'

    Example:

    $settings['quotes'] = array(
    'First quote',
    'Multi
    line
    quote',
    'Third quote',
    'Some text with <b>HTML</b> code!',
    'Any single quotes \' must be escaped with a backslash',
    'A quote with a <a href="http://www.phpjunkyard.com">link</a>!',
    'Some long text
    that stretches over several
    lines and contains some
    <b>HTML</b> code and ends
    with a <a href="http://www.phpjunkyard.com">link</a>',
    );


    $settings['display_type'] If set to 1 RanTex will print out valid Javascript code. This is useful if you want to print random text/quotes on static HTML pages using Javascript:

    <script type="text/javascript" src="rantex.php"></script>


    If set to 0 RanTex will print just the text as received without any formatting. Use this mode if you are using RanTex as a PHP include or with SSI (*.shtml files):

    "<?php include 'rantex.php'; ?>

    $settings['allow_otf'] If set to 1 RanTex will allow changing display_type setting on-the-fly (see below) Set to 0 to only allow hard-coded settings (as set in the rantex.php file).

Save changes and upload the edited rantex.php file to your server.

-> Changing settings on-the-fly

You can also modify RanTex display_type settings on-the-fly simply by passing proper values to the script using query string (when using RanTex as Javascript SRC URL) or variables (when using RanTex as a PHP include).

For changing settings on-the-fly to work variable $settings['allow_otf'] must be set to 1 (see above)!

Operating mode ($settings['display_type']) can be changed using $_GET['type'] variable. This might sound a bit confusing, but here are a few examples:

If your default $settings['display_type'] is 0 (PHP include) but would like to use the same script to show quotes in Javascript you can use this code:

<script type="text/javascript" src="rantex.php?type=1"></script>

On the other hand if your default mode is 1 (Javascript) you can use the same script as an include like this:

<?php $_GET['type'] = 0; include 'rantex.php'; ?>

The same code is used in the test.php file, have a look if interested.

A lot of time and effort went into developing RanTex and other PHPJunkyard scripts. That's why this script requires attribution. In other words: if you are using this script you are required to place a link to PHPJunkyard on your website. This is all I require in exchange for this free script, please support my work by placing a link on your website. It can be as simple as a short text link.

-> Don't want to place a link?

If you want to use RanTex but would prefer (for any reason) not to place a link to PHPJunkyard on your website you can attribute by sending a small donation. Any amount. Donations help keep PHPJunkyard website and scripts alive.

-> Link suggestions

1. Simple text link
Random Text

2 "Powered by" simple text link
Powered by Random Text

3. Text link with description
Random Text - get this and other free PHP scripts from PHPJunkyard.

TIP: Get more link suggestions on the PHPJunkyard link to us page!

» HELP and Troubleshooting

1. What is CHMOD and FTP?

I have prepared a simple FTP and CHMOD tutorial which will help you FTP files to your server and set correct CHMOD settings.

2. How do I paste Javascript code into my web page? I tried pasting it but it only shows code, not random links?

Try using a simple trick from my Cut and paste code into HTML document tutorial.

3. I get an error message when I open rantex.php in the browser?

You probably made an error when editing rantex.php file. Double-check all the instructions in the Modifying default settings section above. Try to follow the original script setup/examples and modify the script step-by-step (make one change, test it, make another change, test it, ...)

4. The on-the-fly changes have no effect

Make sure you have $settings['allow_otf'] set to 1 and are passing correct values to the script. If you pass invalid values the default settings will be used

 

Since these scripts are free no support is guaranteed. If you can't get the script to work please go through this readme file again carefully and repeat the installation step-by-step (also delete old files and folders from the server). Also please feel free to post any questions or problems you might have in PHPJunkyard forum!

» Stay updated!

Join my FREE newsletter and you will be notified about new scripts, new versions of the existing scripts and other important news from PHPJunkYard.
Click here for more info

» Please rate this script

If you like this script please rate it or even write a review at:

Rate this Script @ Hot Scripts

Rate this Script @ The PHP Resource Index

Best regards,

Klemen Stirn
PHP JunkYard
http://www.PHPJunkYard.com