470,833 Members | 1,967 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Random Selection of String Value

Please tell me how I can randomly select a string from a limited set
of string, and then use it in links.

With equal probability, suppose half the time I want
to form a link to domain.com/1234/page.htm and half the time I
want to link to domain.com/5678/page.htm . I would like to be
able to put something into my link such as:
domain.com/<?php ... WHAT GOES HERE? ... ?>/page.htm

If possible, I'd like to use a method that will put either 1234 or
5678 into a variable, so that, once it's randomly chosen for a
document sent to the browser, then numerous references to that
same string value can be used on the page.

Thank you.

--

Mike Lepore -- lepore at bestweb dot net delete the 5

Jul 17 '05 #1
2 3405
Mike Lepore wrote:
Please tell me how I can randomly select a string from a limited set
of string, and then use it in links.

With equal probability, suppose half the time I want
to form a link to domain.com/1234/page.htm and half the time I
want to link to domain.com/5678/page.htm . I would like to be
able to put something into my link such as:
domain.com/<?php ... WHAT GOES HERE? ... ?>/page.htm

If possible, I'd like to use a method that will put either 1234 or
5678 into a variable, so that, once it's randomly chosen for a
document sent to the browser, then numerous references to that
same string value can be used on the page.


<?php
$dir = '12345';
if (rand(0,1)) {
$dir = '5678';
}
?>

<a href="http://domain.com/<?=$dir;?>/page.htm">

Hope this helps
Jul 17 '05 #2
"Mike Lepore" <le*****@bestweb.net> wrote in message news:<10*************@corp.supernews.com>...
Please tell me how I can randomly select a string from a limited set
of string, and then use it in links.

With equal probability, suppose half the time I want
to form a link to domain.com/1234/page.htm and half the time I
want to link to domain.com/5678/page.htm . I would like to be
able to put something into my link such as:
domain.com/<?php ... WHAT GOES HERE? ... ?>/page.htm

If possible, I'd like to use a method that will put either 1234 or
5678 into a variable, so that, once it's randomly chosen for a
document sent to the browser, then numerous references to that
same string value can be used on the page.

Thank you.


$pages = array(1234, 5678);
$page = array_rand($pages);
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tim Churches | last post: by
3 posts views Thread by Jennie Friesen | last post: by
4 posts views Thread by Jack | last post: by
8 posts views Thread by Kari Lavikka | last post: by
5 posts views Thread by jordi | last post: by
19 posts views Thread by Boris Borcic | last post: by
1 post views Thread by Sahus Pilwal | last post: by
3 posts views Thread by duffint | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.