convert a string to integer

This is a discussion on convert a string to integer within the PHP General forums, part of the PHP Programming Forums category; Hi, i know this topic is obvious but i have a strange behavior and i'm getting crazy. my stored ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-28-2008
Alain Roger
 
Posts: n/a
Default convert a string to integer

Hi,

i know this topic is obvious but i have a strange behavior and i'm getting
crazy.

my stored procedure returns me a string.
string can be an email or a message error => '-1', '-2', '-3'

when i check if the string contains only digit, i use ctype_digit(mystring)
but any way it returns me false... i suppose that for -1, -2, -3 the "-" is
taken as character and not a digit.
i tried also to cast it before into integer thanks
ctype_digit((int)mystring), but it does not work.

so how can i solve this issue ?

thx

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #2 (permalink)  
Old 03-28-2008
Casey
 
Posts: n/a
Default Re: [PHP] convert a string to integer

On Fri, Mar 28, 2008 at 12:48 AM, Alain Roger <raf.news@gmail.com> wrote:
> Hi,
>
> i know this topic is obvious but i have a strange behavior and i'm getting
> crazy.
>
> my stored procedure returns me a string.
> string can be an email or a message error => '-1', '-2', '-3'
>
> when i check if the string contains only digit, i use ctype_digit(mystring)
> but any way it returns me false... i suppose that for -1, -2, -3 the "-" is
> taken as character and not a digit.
> i tried also to cast it before into integer thanks
> ctype_digit((int)mystring), but it does not work.
>
> so how can i solve this issue ?
>
> thx
>
> --
> Alain
> ------------------------------------
> Windows XP SP2
> PostgreSQL 8.2.4 / MS SQL server 2005
> Apache 2.2.4
> PHP 5.2.4
> C# 2005-2008
>


is_numeric()

--
-Casey
Reply With Quote
  #3 (permalink)  
Old 03-28-2008
Simon Welsh
 
Posts: n/a
Default Re: [PHP] convert a string to integer


On 28/03/2008, at 8:48, Alain Roger wrote:
> Hi,
>
> i know this topic is obvious but i have a strange behavior and i'm
> getting
> crazy.
>
> my stored procedure returns me a string.
> string can be an email or a message error => '-1', '-2', '-3'
>
> when i check if the string contains only digit, i use
> ctype_digit(mystring)
> but any way it returns me false... i suppose that for -1, -2, -3 the
> "-" is
> taken as character and not a digit.
> i tried also to cast it before into integer thanks
> ctype_digit((int)mystring), but it does not work.
>
> so how can i solve this issue ?
>
> thx
>
> --
> Alain
> ------------------------------------
> Windows XP SP2
> PostgreSQL 8.2.4 / MS SQL server 2005
> Apache 2.2.4
> PHP 5.2.4
> C# 2005-2008


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."
---
Simon Welsh
Admin of http://simon.geek.nz/

Windows is a joke operating system. Hell, it's not even an operating
system. NT is Not Tough enough for me either. 95 is how may times it
will crash an hour.

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


Reply With Quote
  #4 (permalink)  
Old 03-28-2008
Alain Roger
 
Posts: n/a
Default Re: [PHP] convert a string to integer

thx a lot... i completly skipped this one...i don't know why :-(
now it works

On Fri, Mar 28, 2008 at 8:55 AM, Simon Welsh <simon@welsh.co.nz> wrote:

>
> On 28/03/2008, at 8:48, Alain Roger wrote:
> > Hi,
> >
> > i know this topic is obvious but i have a strange behavior and i'm
> > getting
> > crazy.
> >
> > my stored procedure returns me a string.
> > string can be an email or a message error => '-1', '-2', '-3'
> >
> > when i check if the string contains only digit, i use
> > ctype_digit(mystring)
> > but any way it returns me false... i suppose that for -1, -2, -3 the
> > "-" is
> > taken as character and not a digit.
> > i tried also to cast it before into integer thanks
> > ctype_digit((int)mystring), but it does not work.
> >
> > so how can i solve this issue ?
> >
> > thx
> >
> > --
> > Alain
> > ------------------------------------
> > Windows XP SP2
> > PostgreSQL 8.2.4 / MS SQL server 2005
> > Apache 2.2.4
> > PHP 5.2.4
> > C# 2005-2008

>
> 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."
> ---
> Simon Welsh
> Admin of http://simon.geek.nz/
>
> Windows is a joke operating system. Hell, it's not even an operating
> system. NT is Not Tough enough for me either. 95 is how may times it
> will crash an hour.
>
> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:24 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0