Richard Lynch wrote:
> 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?

look at pron for half an hour and all of a sudden your
code will rewrite itself.

or alternatively learn to write regular expressions - for
which me recommend RTFM - I assume they still advise actually reading
at school?

> 
> 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...

especially when your doing it for him ;-)

> 

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

Reply via email to