Results 1 to 3 of 3

Thread: need help with php code

  1. #1
    Join Date
    Jul 2007
    Posts
    34
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default need help with php code

    Hi

    I use this script wich randomly returns a line of text from a txt file. The text are randomly choosed line by line. My Question : is it possible to modify this code so that the text can be over multiple lines divided by a *divider* from each other?

    Code:
    $quoteFile = "quotes.txt";  //File holding quotes
    
       $fp = fopen($quoteFile, "r");   //Opens file for read
       $content = fread($fp, filesize($quoteFile));
       $quotes = explode("\n",$content);   //Put quotes into array
       fclose($fp);   //Close the file
    
    srand((double) microtime()*10000000);
    $index = (rand(1, sizeof($quotes)) - 1); //Pick random quote

  2. #2
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    If you want to use something other than newlines as dividers change this line -

    Quote Originally Posted by Marquis View Post
    Code:
    $quotes = explode("\n",$content);   //Put quotes into array
    Just replace "\n" with whatever you want to use as a divider instead. (\n is the symbol for newline)

  3. #3
    Join Date
    Jul 2007
    Posts
    34
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by keyboard View Post
    If you want to use something other than newlines as dividers change this line -



    Just replace "\n" with whatever you want to use as a divider instead. (\n is the symbol for newline)
    thank you very much... just another question. same script includes img with code below. I wish to make $verzeichnis = "img/thumbs/"; relative to server root path. I tried different ways with $_SERVER['DOCUMENT_ROOT but no one works. Is it possible to do this?

    Code:
    <?php 
    $verzeichnis = "img/thumbs/";
    $bildtyp = array("gif","jpg","png","bmp");
    $quelle = dir($verzeichnis);
    $bildname = array();
    $link_target = ('_parent') ;
    $linkrel = ('nofollow') ;
    
    while($datei = $quelle->read()){$format = substr(strrchr($datei,".") ,1);
    if (in_array($format,$bildtyp)){$bildname[] = $datei;}}
    $quelle->close();
    srand((double) microtime()*10000000);
    $typ = array_rand($bildname);

Similar Threads

  1. Replies: 25
    Last Post: 09-13-2016, 05:36 AM
  2. Replies: 3
    Last Post: 05-12-2011, 03:43 AM
  3. Secret code / hidden message / obfuscated code - ???
    By newbie01.others in forum JavaScript
    Replies: 2
    Last Post: 01-14-2011, 11:29 AM
  4. Replies: 15
    Last Post: 06-11-2009, 12:27 PM
  5. Replies: 2
    Last Post: 10-27-2008, 05:16 AM

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
  •