Str replace multi digit numbers problem

Discussion in 'PHP' started by xtreme fever, May 20, 2008.

  1. #1
    Hello,

    I am trying to set up a form to auto select a design in a menu and I'm having a problem with 2+ digit numbers... For example, request info for design 10.

    html?design=10

    $design = $_GET['design'];
    $design = str_replace("0", "Select Design", $design);
    $design = str_replace("1", "Design 1", $design);
    $design = str_replace("10", "Design 10", $design);

    Design 10 menu output field = Design1Select Design

    How can I fix this so that my output menu field prints "Design 10"?

    Thanks
     
    xtreme fever, May 20, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try doing it this way, starting with the larger numbers:

    
    $match = array(10,1,0);
    $replace = array('Design 10','Design 1','Select Design');
    
    $design = str_replace($match,$replace,(int)$_GET['design']);
    
    
    PHP:
     
    jestep, May 20, 2008 IP
  3. xtreme fever

    xtreme fever Active Member

    Messages:
    472
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    95
    #3
    I'm still having an issue. I'll just use a,b,c... instead of 1,2,3...

    Thanks

     
    xtreme fever, May 20, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Make sure you remove the (int) if you go with that method.
     
    jestep, May 20, 2008 IP
  5. xtreme fever

    xtreme fever Active Member

    Messages:
    472
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    95
    #5
    Right, thanks

     
    xtreme fever, May 20, 2008 IP