Re: Re: String handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As I understand, you're trying to check if the passed value is an
integer or not and then check it's value right?

Use the TYPECASTING technique. 
example:
$var = (int) $var;

In this case you're converting ur $var to integer before processing it.
Typecasting is a very well known technique in any programming language.

The alternative is to check the type of ur $var. That is using
is_int($var) if it holds then compare.

However the best way is to limit the user on the client side to enter
the right datatype like a JS validator to see if the user entered the
right type of info & then an slight type checking on the server side
to make ur life easier.

Hope this was useful.

On Mon, 04 Oct 2004 23:35:25 +1000, Ross Honniball
<ross@xxxxxxxxxxxxxxxxxxx> wrote:
> I usually just add zero to a string to force a conversion.
> 
> eg. $x = '123'; $int = $x + 0;
> 
> You might also want to use the is_numeric() function to validate data first?
> 
> 
> 
> At 10:47 AM 3/10/2004, you wrote:
> >Try using the intval() function
> >
> >intval('1000');     // will result in 1000
> >intval('1000ABC');  // will result in 1000
> >
> >Amit
> >www.digitalamit.com
> >
> >Darryl wrote:
> >>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
> 
> .
> . Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
> .
> 
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 



-- 
M.Saleh.E.G
97150-4779817

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux