Yeah, I thought so seeing as I had done it like that previously, turns out
it was something else that was causing the problem ":D

Thanks anyhow
":D

-----Original Message-----
From: Hutchins, Richard [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 30, 2004 5:43 PM
To: 'Darryl'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] String handling

If you use the value from a text box in a mathematical equation or
comparison, PHP will automatically attempt to handle it as an integer or
some other numeric type (e.g., float). So if you did something like: 

if($_POST["myvar"] < 10000){

...

}

PHP would handle $_POST["myvar"] as an integer automatically since it's
being compared to another integer. Chapter 7: Type Juggling in the PHP
manual sums this all up nicely.

If you want to explicitly cast your variable as an integer, you can do
either:

settype($_POST["myvar"], "integer");

OR

$intval = (int) $_POST["myvar"];

Either way, you're still going to want to do some data validation to make
sure that the value in your text box is a number and not a text string
before you convert it because you may get unexpected results if you try to
convert a string to an integer depending on the contents of the string. The
String Conversion section in the Strings chapter of the PHP documentation
provides examples of how strings get converted to integers (and other types)
by PHP.

I am certainly no expert on type casting and have been stung by problems
like this in the past. But check out the parts of the PHP documentation I
cited and you should be able to figure out what needs to be done.

HTH,
Rich



> -----Original Message-----
> From: Darryl [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 30, 2004 10:42 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] String handling
> 
> 
> Hay,
> 
>  
> 
> Is there a way to make a string into an integer?
> 
> I have a value coming from a textbox and I want to check if 
> the amount in it
> is < 10000.
> 
>  
> 
> Thanks,
> 
> Darryl
> 
> 

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

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

Reply via email to