is_int()
I have the following two lines of code:
!isset($_POST['rows']) ? $rows = "10" : $rows = trim($_POST['rows']);
!is_int($_POST['rows']) ? $rows = "10" : $rows = trim($_POST['rows']);
What this is ment to do is check if $_POST['rows'] is set. If not, then set it to "10" else just leave it.
Next, it checks if $_POST['rows'] is an integer or not. If it isn't, then set it to "10" else, just leave it.
No matter what number or text I send, it always returns a "10"
I tried looking on php.net for the is_int() function use, but, that didn't really help much...
Busy posted this at 08:14 — 14th February 2005.
He has: 6,151 posts
Joined: May 2001
tried printing the values inbetween?
!isset($_POST['rows']) ? $rows = "10" : $rows = trim($_POST['rows']);
echo "rows = $rows";
!is_int($_POST['rows']) ? $rows = "10" : $rows = trim($_POST['rows']);
echo "rows now = $rows";
CptAwesome posted this at 00:47 — 15th February 2005.
He has: 370 posts
Joined: Dec 2004
Ah, I think your problem is trim:
When you use trim, it becomes a string, instead of an interger, and will always fail is_int(); (thats my best guess)
I'd suggest doing just an is_int anyway, if it fails that, then it's obviously going to fail isset right? so, I owuld simply have:
!$is_int($_POST['rows'] ? $_POST['rows'] = 10;
that pretty much covers all your bases, but I would set a min value and a max value if you haven't already.
Renegade posted this at 02:52 — 15th February 2005.
He has: 3,022 posts
Joined: Oct 2002
The problem has been solved. Thank you.
It turned out that passing anything through POST makes it a string, so I had to use is_gnumeric() instead.
CptAwesome posted this at 06:56 — 15th February 2005.
He has: 370 posts
Joined: Dec 2004
Ah, I was testing it with $_GET
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.