RanTex - PHP Random Text script

INDEX

» ACKNOWLEDGEMENT

Please support our free PHP scripts by linking to us or sending a donation. Thank you!

» Installation

Please take 5 minutes to read the installation instructions carefully and thoroughly! Doing so will ensure a proper and easy installation.

 

#1: Quick install

  1. Connect with FTP to the public folder of your server where the rest of your Web site is.

    TIP: The public folder is usually called "public_html", "www", "site" or "htdocs".

    TIP: Learn how to FTP files by reading this FTP and CHMOD tutorial

  2. Create a new folder where you will install this script. Name it anything you like, for example, "rantex" or "quotes".
    Example: /public_html/rantex
    Corresponding URL: https://www.example.com/rantex

  3. Upload all RanTex files to your server. PHP files must be transferred in ASCII mode and images in BINARY mode.

    TIP: Most FTP clients will automatically select the proper transfer mode so you needn't worry about it.

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

Your browser should show a sample page with two random quotes displayed. Refresh the page to see the text change.

 

#2: 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="https://example.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!

 

Find this script useful? Please support our free PHP scripts by linking to us or sending a donation. Thank you!

 

#3: 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. The 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. You must escape any single quotes inside the text 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="https://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="https://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.

 

#4: Changing settings on-the-fly

You can also modify RanTex display_type settings on-the-fly 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.

Are links not your thing? You can attribute by sending a small donation. Any amount will help keep PHPJunkyard website and free scripts alive. Thank you!

Link suggestions

1. Simple text link: Random Text

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

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

For up-to-date help and troubleshooting guides, please visit:
PHPJunkyard Support

» Stay updated!

Join our FREE newsletter and we will notify you about new scripts, new versions of the existing scripts, and other important news from PHPJunkyard.
Click here for more info

» Get more useful FREE scripts!

Looking for more PHP scripts? Here is a list of PHPJunkyard FREE scripts:

» CHANGELOG

Changes in 1.2
- don't cache Javascript

Changes in 1.1
- set correct MIME type for servers sending nosniff header

 

© Copyright PHP Scripts from PHPJunkyard 2004-2022. All rights reserved.