Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 10:22 AM
Mike Lepore
Guest
 
Posts: n/a
Default 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



  #2  
Old July 17th, 2005, 10:22 AM
brommer
Guest
 
Posts: n/a
Default 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
Default 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);
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles