1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Random Quote Generator

Discussion in 'PHP' started by NewTier, Jul 26, 2009.

  1. #1
    <?
    
    $quotes = array();
    
    $content = file_get_contents('quotes.txt');
    
    //gets contents of the quotes.txt file
    
    $quotes = explode("::",$content);
    
    //makes an array of quotes after they are seperated
    
    $total_quotes = count($quotes);
    
    //counts the total number of quotes
    
    echo trim($quotes[mt_rand(0,$total_quotes-1)]);
    
    //echo a random quote :)
    
    ?>
    PHP:
    When I want to use a , instead of a ::
    it doesn't work. How can I make it work with , ?


    Thanks!
     
    NewTier, Jul 26, 2009 IP
    Ibn Juferi likes this.
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Did you mean explode them using comma as delimiter?

    If yes, you shouldn't, because quotes has a lot of commas?
     
    ads2help, Jul 26, 2009 IP
  3. NewTier

    NewTier Notable Member

    Messages:
    2,201
    Likes Received:
    196
    Best Answers:
    0
    Trophy Points:
    250
    #3
    ah but lets say I want to use commas, how do I do it? :)
     
    NewTier, Jul 26, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Like this:

    
    $quotes = explode(",",$content);
    
    PHP:
     
    ads2help, Jul 26, 2009 IP
    NewTier likes this.