Re: Lost in PHP (part 1) ---- Sequle to Lost in Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



GH wrote:

How can I convert it to an integer aslong as it is only a number in the string?

Does it _really_ matter if only a number is passed? If someone passes "abcd" and it's converted to an integer, it'll be zero. Then your query will not return any rows (which you're already testing for, anyhow, right?) and be handled accordingly. Who cares if they pass "104abcd"? It'll just be converted to 104 and see if a matching record exists.


I think you're getting caught up in too many tests. If you're expecting an integer, MAKE it an integer, then run your query. 99.9% of your values are going to come through correct if they are coming from your program, right? Just silently ignore the rest because it's someone screwing around.

If, however, you _really_ want to ensure $_GET['api'] is _only_ numbers, then you can use

if(!isset($_GET['api']) || preg_match('/[^0-9]/',$_GET['api']))
{ echo 'API is not all numbers'; }

or

if(isset($_GET['api']) && preg_match('/^[0-9]+$/',$_GET['api']))
{ echo 'API is a number only'; }

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux