• First create a text file with ads.txt extension. Each ad has its unique HTML code. For example :

    <a href="http://www.mysite.com">Demo Text Link</a>

  • Write a function to handle ads. Example:

    // Function to display random ads from a list
    function showRandomAD($ADnumber = 1){
    // Loading the ad list into an array
    $adList = file('ads.txt');

    // Check the total number of ads
    $numberOfADs = sizeof($adList);

    // Initialize the random generator
    list($usec, $sec) = explode(' ', microtime());
    srand((float) $sec + ((float) $usec * 100000));

    // Initialize the ads counter
    $adCount = 0;

    // Loop to display the requeste number of ads
    while ($adCount++ < $ADnumber) {
    // Generate random ad id
    $actAD = rand(0, $numberOfADs-1);
    // Display the above generated ad from the array
    echo $adList[$actAD].'<br/>';

  • All the lines from the file is stored in the array.
  • The function srand() selects the adds randomly from the array.
  • Create a simple php file and ember the statement <?php showRandomAD(3); ?> to demonstrate the use of rotator ad.

Posted in: PHP

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677