Debt Consolidation - Find services - Debt Consolidation - Debt Consolidation - Free Ecards

PDA

View Full Version : Str replace multi digit numbers problem


xtreme fever
May 20th 2008, 6:29 am
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

jestep
May 20th 2008, 6:50 am
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']);

xtreme fever
May 20th 2008, 7:03 am
I'm still having an issue. I'll just use a,b,c... instead of 1,2,3...

Thanks

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']);

jestep
May 20th 2008, 7:06 am
Make sure you remove the (int) if you go with that method.

xtreme fever
May 20th 2008, 7:07 am
Right, thanks

Make sure you remove the (int) if you go with that method.