Re: Matching numbers 1-100

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, February 3, 2007 11:09 am, Wikus Moller wrote:
> I want to know if anyone can help me with my code which matches a
> number to a range e.g. 1-15 and echoes an image if the number is in
> the range.
>
> The code would use the if statement and check if a variable for
> example 5  matches the range like 4-10 and if it does it echoes a
> certain image.
>
> Anyone know which function I should use and what regex I should use?

This sounds a heck of a lot like a homework assignment...

Oh well.

<?php
$input = '42';
$number = (int) $input; //make sure it's a number
if ($number >= 1 and $number <= 15) echo "an image";

This will be problematic if you need to detect '0', since 'a' turns
into '0' in the typecast.  In that case, you'd want
http://php.net/pcre


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux