473,509 Members | 8,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jul 16 '05 #1
2 2446
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
Jul 16 '05 #2
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" <ne**@andyjeffries.remove.co.uk> wrote in message
news:pa****************************@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

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6528
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
6
6309
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
4
1787
by: Derek | last post by:
I have the following script in a page and it gets an error in IE 6. Says something about an invalid argument but the line number doesn't help since I can't see the javascript code when viewing...
7
1852
by: mike | last post by:
Hello, I am kind of new to this javascript stuff and I am constantly having problems trying to get my webpage validated. I have the following <script>printdate();</script> and when I validate it...
5
2963
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
8
5452
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
3694
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
5519
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
3680
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
4
6278
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.