Help with a PHP script

This is a discussion on Help with a PHP script within the PHP Language forums, part of the PHP Programming Forums category; I've got a cgi script that allows me to add the output of a php script to an html ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-11-2003
\(a\)
 
Posts: n/a
Default Help with a PHP script

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>

The contents of text.txt would be something like this:

This is yahoo
yahoo is a search engine
search using yahoo

Thanks for the help.


Reply With Quote
  #2 (permalink)  
Old 09-11-2003
Andy Jeffries
 
Posts: n/a
Default Re: Help with a PHP script

On Thu, 11 Sep 2003 06:32:04 +0000, (a) wrote:
> 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.


Assuming your text.txt file isn't too big and is in the same directory as
/script.php :

<?php

// Slurp all the lines of test.txt in to an array
$data = file("test.txt");

// Print a random (rand) line from 0 (start of the array) to
// the end of the array (count($array)-1)
print $data[rand(0, count($data)-1)];

?>

If this was a homework assignment, I'll kill you in your own kitchen!!!
:-)

Cheers,



Andy
Reply With Quote
  #3 (permalink)  
Old 09-13-2003
\(a\)
 
Posts: n/a
Default Re: Help with a PHP script

Nope, not homework, would never cheat.

Just I'm not a programmer and it was faster to ask a question in an expert
forum then to have to learn php to solve a single problem I was having.


"Andy Jeffries" <news@andyjeffries.remove.co.uk> wrote in message
news:pan.2003.09.11.13.16.38.928918@andyjeffries.r emove.co.uk...
> On Thu, 11 Sep 2003 06:32:04 +0000, (a) wrote:
> > 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.

>
> Assuming your text.txt file isn't too big and is in the same directory as
> /script.php :
>
> <?php
>
> // Slurp all the lines of test.txt in to an array
> $data = file("test.txt");
>
> // Print a random (rand) line from 0 (start of the array) to
> // the end of the array (count($array)-1)
> print $data[rand(0, count($data)-1)];
>
> ?>
>
> If this was a homework assignment, I'll kill you in your own kitchen!!!
> :-)
>
> Cheers,
>
>
>
> Andy



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:19 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0