Re: Help with matching numbers 0-100

From: Date: Sat, 03 Feb 2007 17:43:11 +0000
Subject: Re: Help with matching numbers 0-100
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-248246@lists.php.net to get a copy of this message
Chilling Lounge Admin wrote:
Hi. 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? Thanx
if(preg_match('/(\d+)/', $variable, $matches) {
      if($matches[1] > N && $matches[1] < N2) {
          /  do your thing
     }
} <?php $variable = "image-number 16. jpg"; if(preg_match('/(\d+)/', $variable, $matches)) {
      if($matches[1] > 4 && $matches[1] < 20) {
          echo $matches[1] . "  is in range\n";
     }
     else echo $matches[1] . " out of range\n";
} ?> -- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/

« previous php.general (#248246) next »