Random Selection of String Value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Lepore

    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



  • brommer

    #2
    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

    Comment

    • Chung Leong

      #3
      Re: Random Selection of String Value

      "Mike Lepore" <lepor5e@bestwe b.net> wrote in message news:<10o6g2qm9 u641ea@corp.sup ernews.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($pag es);

      Comment

      Working...