PHP Script help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raster
    Confirmed User
    • Aug 2003
    • 784

    #1

    PHP Script help

    I've got a cgi script that allows me to add the output of a php script to an html page using the following line of code.

    #insert : http://www.url.com/sript.php#

    What I'm wondering is if someone could write me a couple of lines of code for script.php that would randomly select one line of information from a text file called text.txt.

    This way, if I had the following line in my html file, the place where #insert : http://www.url.com/sript.php# is located, would be replaced by a random line of text from text.txt.

    <a href="http://www.yahoo.com">#insert : http://www.url.com/sript.php#</a>

    Thanks
  • JSA Matt
    So Fucking Banned
    • Aug 2003
    • 5464

    #2
    keep it simple : )

    PHP Code:
    <?php
        $file        = "random.txt";
        $file_Content    = file($file);
    
        if (count($file_Content) > 0)    {
            $line = $file_Content[rand(0,count($file_Content)-1)];
        
        echo $line;
        }
    ?>

    Comment

    • myneid
      Confirmed User
      • Jan 2003
      • 736

      #3
      i see now you beat me to it
      Tanguy 0x7a69 inc. Programmer/President/CEO
      http://www.0x7a69.com
      A Leader in Programming since 1996
      PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting

      Comment

      • raster
        Confirmed User
        • Aug 2003
        • 784

        #4
        Originally posted by JSA Matt
        keep it simple : )

        PHP Code:
        <?php
            $file        = "random.txt";
            $file_Content    = file($file);
        
            if (count($file_Content) > 0)    {
                $line = $file_Content[rand(0,count($file_Content)-1)];
            
            echo $line;
            }
        ?>
        Thanks very much, works great.

        Comment

        Working...