Page 1 of 1

is_numeric issue

Posted: Tue Jan 22, 2008 7:29 am
by PhpDog
The following script never runs the 'else' part of the code, but I don't understand why. Any thoughts appreciated.

if(is_numeric($mortgage))
{
$table =
"
<table width='100%' border='0' cellpadding='1'>
<tr>
<td class='warning'><div align='center'>That's a number!</div></td>
</tr>
</table>
";

} else {

$table =
"
<table width='100%' border='0' cellpadding='1'>
<tr>
<td class='warning'><div align='center'>Mortgage number field must contain numbers ONLY</div></td>
</tr>
</table>
";
}

Re: is_numeric issue

Posted: Tue Jan 22, 2008 7:59 am
by Zoxive

Code: Select all

var_dump($mortgage);
PHP Manual wrote: is_numeric
Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.

Re: is_numeric issue

Posted: Tue Jan 22, 2008 8:08 am
by PhpDog
Thanks.

I found the problem to be elsewhere in the code. To try and test the input I had $mortgage.length instead of strlen($mortgage), so a test failed upon which my code above replied.

Switching between programming languages causes memory failure some days! :)