On Sat, February 3, 2007 10:55 am, Chilling Lounge Admin wrote: > I need help with matching a variable. The variable would be e.g. 0-15 > , 16-30 etc. and when the variable is equal to a certain range, it > would echo an image. > > Does anyone know what function I should use? preg_match? > > The code would be something like > > if(preg_match("[16-30]",$variable)) > { > echo "image"; > } > > but the above code doesn't work. How do I fix it? Deja Vu! <?php if (!preg_match('/^[0-9]+$/', $input)){ die("invalid input\n"); } $input = (int) $input; switch (true){ case $input < 0: die("invalid input\n"); break; case $input <= 15: echo "image 1 to 15\n"; break; case $input <= 30: echo "image 16 to 30\n"; break; default: die("invalid input\n"); break; } ?> If this is homework, you'd better go hire a tutor NOW, because it ain't gonna get any easier than this... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php