Connecting Tech Pros Worldwide Forums | Help | Site Map

Random Selection of String Value

Mike Lepore
Guest
 
Posts: n/a
#1: Jul 17 '05
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




brommer
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Random Selection of String Value


Mike Lepore wrote:[color=blue]
> 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.
>[/color]

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

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



Hope this helps
Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Random Selection of String Value


"Mike Lepore" <lepor5e@bestweb.net> wrote in message news:<10o6g2qm9u641ea@corp.supernews.com>...[color=blue]
> 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.[/color]

$pages = array(1234, 5678);
$page = array_rand($pages);
Closed Thread