Results 1 to 9 of 9

Thread: Script to show random quotes

  1. #1
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post Script to show random quotes

    Hi, i am looking for a script that can display random quotes that i have added. I want the script to display a diferent quote every time the page is refreshed. Help me please.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In what language?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    i have seen some written in PHP and some in Javascript but i was thinking if there was someway to use PHP and have it linking to an external file where the qoutes are kept.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yep, that's fine:
    Code:
    <?php
      function random_choice($arr) {
        return $arr[rand(0, count($arr) - 1) % count($arr)];
      }
    
      print random_choice(file('quotes.txt'));
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post

    Thanks a lot

  6. #6
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Yep, that's fine:
    Code:
    <?php
      function random_choice($arr) {
        return $arr[rand(0, count($arr) - 1) % count($arr)];
      }
    
      print random_choice(file('quotes.txt'));
    ?>
    Sorry i have a little problem, how would i set out the quotes.txt file?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Plaintext or HTML, each quote on a separate line.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post

    can you give me an example please, becasue i have tried a new quote on a new line, but it is not working.

  9. #9
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    from what i understand, you should open a plain text editor like notepad, each quote should be on a different line, then save it as quotes.txt
    Code:
    "something something something"
    "blah blah blah"
    "somethingelse somethingelse somethingelse"
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

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