My code uses:
$test = intval($mybb->input['id']);
and when it contains numbers it works!
However my input contains letters, numbers and they are separated by a dash symbol: this-is-a-test
What are the alternatives of intval
Thanks
My code uses:
$test = intval($mybb->input['id']);
and when it contains numbers it works!
However my input contains letters, numbers and they are separated by a dash symbol: this-is-a-test
What are the alternatives of intval
Thanks
It depends. What exactly are you wanting to do with the id value other than simply assigning it to the $test variable?
More to the point, what exactly are you trying to -extract- from the ID?
Intval works perfectly well. If you tell it to intval(“im-a-daisy”), you’ll get the integer value of that string; that being 0.
I am sorry guys for making you guess.
I wanna do some like this:
$test = intval($mybb->input['id']);
if (!validator($test))
{
error;
}
now here is the function:
function validator($test)
{
global $db;
$query = $db->simple_select("threads", "*", "id LIKE '%".$db->escape_string_like($test)."%'");
$thread = $db->fetch_array($query);
if ($thread['id'])
{
return TRUE;
}
else
{
return FALSE;
}
}
The problem is that ID will not always be numeric in fact most of the time it will look like this: this-is-test
so it sounds to me you’re more attempting to do:
if(is_numeric($mybb->input['id']) && !validator($mybb->input['id'])) { error; }
(Note that is_numeric will find -ALL FORMS- of numeric strings, not just integers.)
thanks so much that works great!
I’m wondering if the Ids are to never be floats (i.e. have a “.”) that maybe
ctype_digit might be better?
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.