PHP Code:
function var_between ($string, $min, $max) {
return (strlen($string) >= $min && strlen($string) <= $max);
}
var_dump(var_between('bla', 5, 20)); // false
var_dump(var_between('blaaat', 5, 20)); // true
There you go. Does in 1 line the same as what you do in 20 (but returns a proper boolean instead of 1 / 0).
Random note: it's not a parse error when the input doesn't follow the expected patterns, certainly not in a softtyped language like PHP. Parse errors occur when your source cannot be parsed and in fact already make sure your function has the valid amount of arguments. Just try calling your function with just 2 parameters: it never ever reaches even the first line, so your entire validation there will never run.
Also, suppose someone just wants to know if a parameter is a max of 10 chars:
PHP Code:
var_between($string, 0, 10);
Now your function echo's a silly parse error while it's a completely valid use of the function.
And on a final note for now: BABO!
(For those who have not had the pleasure of following a class by Frank Brokken: Blanks Around Binary Operators, ie, put some spaces between your conditions and echo's).