Connecting Tech Pros Worldwide Help | Site Map

Random Selection of String Value

  #1  
Old July 17th, 2005, 10:22 AM
Mike Lepore
Guest
 
Posts: n/a
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



  #2  
Old July 17th, 2005, 10:22 AM
brommer
Guest
 
Posts: n/a

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
  #3  
Old July 17th, 2005, 10:23 AM
Chung Leong
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
find test answers in JAVASCRIPT/ source code emily224 answers 4 September 6th, 2007 02:12 PM
XML Help Mark Cooney answers 4 February 21st, 2007 11:05 AM
CountrySelector Control : help needed Versteijn answers 0 November 18th, 2005 05:54 AM
CountrySelector control Versteijn answers 2 July 20th, 2005 04:03 AM
Need help troubleshooting asp error on XP Terri answers 3 July 19th, 2005 09:39 AM