assume we take user input from a form untreated and assign it to variable $range. We want to be sure this number is a Positive Whole number, since abs() just sets a number to positive or 0, and we dont want decimals...
<?php
if(!is_numeric($range)){
$range=1;
}if(!int($range)){
$range=int_val($range);
}$range=abs($range);?>
for example the input "testing" would return $range =1,
the input "3.578" would return value=3
If the input is null, I am havent tested to see if it gets set to 1 courtesy of int_val or not, but I believe it will be.
I'm sure there's probably a more elegant way to do this using regex, however for an apprentice php coder, this might be a little easier to understand and use.