Re: data type casting to numbers with intval() or doubleval()

From: Wesley Leonard <marshall(at)pacdemon(dot)org>
To: imago <imago(at)imago3d(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: data type casting to numbers with intval() or doubleval()
Date: 2001-04-26 15:50:40
Message-ID: 3AE843D0.AF0C8010@pacdemon.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

I think a regex would be most appropriate here:

<?php

$my_string = "mmm444";

$my_integer = intval(eregi_replace("[a-z]", "", $my_string));

print $my_integer;

?>

This removes all letters and takes the int value. In perl you can remove
everything that's NOT a digit but I didn't figure that out in PHP yet... this
should do for now.

l8er

imago wrote:
>
> I am having a problem with the intval() function
>
> I am using it to take string data and extract the number it would
> represent if only numeric.
>
> $my_integer = intval($my_string)
>
> when the sting is numbers followed by letters -
> $my_string = 4444mmm
> $my_integer = 4444
> it works as expected
>
> but when letters are followed by numbers
> $my_string = mmm4444
> $my_integer = 0
>
> Same problem with doubleval()
>
> What am I missing???? how do I drop the non-numeric parts of a
> string?
>
> imago

--

Wesley Leonard
marshall(at)pacdemon(dot)org

http://www.pacdemon.org
"...I want Linux to be on the cutting edge, and even a bit past the edge,
because what's past the edge today is what's on your desktop tomorrow."
--Linus Torvalds

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Christian Marschalek 2001-04-26 16:45:44 HTTP authentication
Previous Message imago 2001-04-26 15:30:04 data type casting to numbers with intval() or doubleval()