www.webdeveloper.com
Results 1 to 4 of 4

Thread: Is it poss to adapt this code to alternate text instead of images?

  1. #1
    Join Date
    Jun 2008
    Posts
    119

    Is it poss to adapt this code to alternate text instead of images?

    Hi, i have this code which alternates an image when ever a user visits the site or refreshes their browser, the idea is that a series of images are rotated allowing equal coverage on the page.

    Can the code be adapted to rotate text or a whole div and its contents instead of the images?

    Thanks guys.

    The code refers to a count.txt file with value="0"

    Heres the code.

    PHP Code:
    <?php
    $img 
    = array();
    $img[] = '<img src="image1.jpg" />';
    $img[] = '<img src="image2.jpg" />';

    $count = (int)file_get_contents('count.txt');
     
    echo 
    $img[$count];
     
    if (
    $count == count($img) - 1){
      
    $count 0;
    }else{
      
    $count++;
    }
    $file 'count.txt';
    $f fopen($file'w');

    fwrite($f$count);
    fclose($f);
    ?>
    Last edited by rodd1000; 12-04-2009 at 07:12 AM.

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    You can just set the contents of the $img array to whatever you need to display:

    PHP Code:
    $img[] = '<div>Textual content!</div>';
    $img[] = '<div>More textual content!</div>';
    $img[] = '<div>Even more textual content!</div>'

  3. #3
    Join Date
    Jun 2008
    Posts
    119
    Thanks for the reply!

    Just tried this but it doesn't rotate the text/div

    heres the page

    HTML
    HTML Code:
    <h1><span class="style12">Restaurant of the month </span><br /> </h1>
                            <div class="altdiv">
    
                  <div>
    PHP Code:
    <?php
    $img 
    = array();
    $img[] = '<div>The original part to this attractive stone built hotel dates back to the 18th century when it was a 

    famous coaching inn. Over the years it has been tastefully extended to offer a wide range of facilities including accommodation, conference facilities, wedding facilities including a civil licence, a restaurant and lounge bar, a hair and beauty salon and a gymnasium. <br />
    </div>'
    ;


    $img[] = '<div>More textual content!</div>';

    $img[] = '<div>Even more textual content!</div>'



     
    $count = (int)file_get_contents('count.txt');
     
    echo 
    $img[$count];
     
    if (
    $count == count($img) - 1){
      
    $count 0;
    }else{
      
    $count++;
    }
    $file 'count.txt';
    $f fopen($file'w');

    fwrite($f$count);
    fclose($f);
    ?>
    Last edited by rodd1000; 12-04-2009 at 08:15 AM.

  4. #4
    Join Date
    Jun 2008
    Posts
    119
    All sorted, forgot to 777,

    Thanks very much for your help, much appreciated!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles