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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to