770 snippets from 1557 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(136)
JavaScript
(123)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
C
(24)
mysql
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Store Procedure
Pygame - Simple p...
Python - Anagram ...
Python - Anagram ...
Converter to bina...
Venture Capital Jobs
New Members
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
impomatic
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Randomly Generate Content
/
Comments
Randomly Generate Content
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
New Comment
Ah
Sun. Mar. 12th, 2006 9:43 PM
Scriptsentials
Wow, you are right, that is more efficient. I would have never thought of doing it that way because most of the time I don't use that method for doing things. I like it. Thanks :D
You learn something new every day.
-----------------------
Proud owner of
scriptsentials.com
and the
Scriptsentials
network.
No code to post.
Reply
Better code
Sun. Mar. 12th, 2006 5:52 PM
Snyke
I think this works by far better and is a lot more readable.
<?php
/*
* This script displays a random string from an array of possible strings.
*/
// Define the strings.
$lines
[
]
=
"This is text 1."
;
$lines
[
]
=
"This is text 2."
;
$lines
[
]
=
"This is text 3."
;
// ...
// Print a random string.
print
(
$lines
[
rand
(
0
,
count
(
$lines
)
-1
)
]
)
;
?>
Reply
Use external file
Sun. Oct. 29th, 2006 1:03 PM
SCoon
Use external file for texts:
<?php
$lines
=
file
(
'texts.txt'
)
;
print
(
$lines
[
rand
(
0
,
count
(
$lines
)
-1
)
]
)
;
?>
Reply
New Comment
You learn something new every day.
-----------------------
Proud owner of scriptsentials.com and the Scriptsentials network.
<?php
/*
* This script displays a random string from an array of possible strings.
*/
// Define the strings.
$lines[] = "This is text 1.";
$lines[] = "This is text 2.";
$lines[] = "This is text 3.";
// ...
// Print a random string.
print($lines[rand(0,count($lines)-1)]);
?>
$lines = file('texts.txt');
print($lines[rand(0,count($lines)-1)]);
?>