Re: Matching numbers 1-100
| From: | Richard Lynch | Date: | Mon, 05 Feb 2007 05:40:28 +0000 |
| Subject: | Re: Matching numbers 1-100 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248317@lists.php.net to get a copy of this message | ||
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?