Reply to Re: Checking if var is integer string or int

Your name:

Reply:


Posted by gosha bine on 04/24/07 09:34

On 24.04.2007 10:00 Jim wrote:
>>> The variable '$pixels' in the code below may be an integer type or an
>>> integer represented as a string type. I need to check if the value is
>>> indeed one of these. Is the following code the simplest I can get?
>>> if (!is_int($pixels) && !ctype_digit($pixels))
>>> {
>>> // some code
>>> }
>
>> Why not just
>>
>> if(!ctype_digit($pixels))
>>
>> ?
>
> Because if I pass in an integer type e.g. ctype_digit(35) it returns
> false as it converts 35 to the characters set equivalent (# symbol in
> my case) .
>
> Jimmy.
>

Use typecast then

if(ctype_digit((string)$var))
var is an int

or

if(ctype_digit("$var"))
var is an int


another possibility, without function calls:

if((string)(int)$var === (string)$var)
var is an int


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация