is_numeric issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

is_numeric issue

Post 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>
";
}
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: is_numeric issue

Post 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.
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: is_numeric issue

Post 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! :)
Post Reply