You are here: Re: need code snippet to verify input strings « PHP Programming Language « IT news, forums, messages
Re: need code snippet to verify input strings

Posted by Mairhtin O'Feannag on 10/01/06 18:00

Thank you Colin. I was expecting 1 and 0 as true and false respectively.
But the test works, so who am I to complain? :)

Thanks again



Colin Fine <news@kindness.demon.co.uk> wrote in
news:efov32$5vd$1$8302bc10@news.demon.co.uk:

> Mairhtin O'Feannag wrote:
>> "Janwillem Borleffs" <jw@jwscripts.com> wrote in
>> news:451ad4ab$0$20623 $dbd4d001@news.euronet.nl:
>>
>>> http://www.php.net/manual/en/function.is-numeric.php
>>
>> Okay, that's a good resource, and a good start. But when testing
>> various values, I get the output :
>>
>> value of x is:1
>> value of id is:222
>> value of id is:
>>
>>
>> where I would expect x and the second id to be 0, not blank. The
>> test, when it succeeds, displays 1, but when it fails, it displays
>> nothing. Test :
>>
>> $testamt = $_POST["amount"];
>> $x = is_numeric($testamt);
>> echo "</br>";
>> echo "value of x is:";
>> echo $x;
>>
>> $id = (int) $_POST["amount"];
>> echo "</br>";
>> echo "value of id is:";
>> echo $id;
>>
>> $id = is_numeric($_POST["date"]);
>> echo "</br>";
>> echo "value of id is:";
>> echo $id;
>>
>> Date is obviously not numeric, in that it contains the "/" character.
>>
>> Any thoughts?
>>
>> Mairhtin
>>
>> P.S. if you see something OBVIOUS, please be gentle, I'm a newbie!!!
>
> PHP has a distinct type 'boolean'. 1, like all non-zero values, is
> converted to TRUE in boolean context, but it is not the same as TRUE.
> 0 is converted to FALSE in boolean context, but it is not the same as
> FALSE.
>
> It would appear from your test that 'echo' reports True as '1' and
> False as blank. I cannot find anything in the on-line manual that says
> how it should behave.
>
> So - don't be worried that it is not reporting what you expect:
>
> if (is_numeric($_id)) {
> ...
> } else {
> ...
> }
>
> will work fine.
>
> Colin
>
> Colin
>

 

Navigation:

[Reply to this 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

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