pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
data type casting to numbers with intval() or doubleval()
3+ messages / 3 participants
[nested] [flat]

* data type casting to numbers with intval() or doubleval()
@ 2001-04-26 15:30  imago <imago@imago3d.com>
  0 siblings, 1 reply; 3+ messages in thread

From: imago @ 2001-04-26 15:30 UTC (permalink / raw)
  To: pgsql-php; +Cc: Wesley Leonard <marshall@pacdemon.org>

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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: data type casting to numbers with intval() or doubleval()
@ 2001-04-26 15:50  Wesley Leonard <marshall@pacdemon.org>
  parent: imago <imago@imago3d.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Wesley Leonard @ 2001-04-26 15:50 UTC (permalink / raw)
  To: imago <imago@imago3d.com>; +Cc: 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@pacdemon.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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Re: data type casting to numbers with intval() or doubleval()
@ 2001-11-16 07:15  Papp Gyozo <pgerzson@freestart.hu>
  parent: Wesley Leonard <marshall@pacdemon.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Papp Gyozo @ 2001-11-16 07:15 UTC (permalink / raw)
  To: Wesley Leonard <marshall@pacdemon.org>; beloshapka@mnogo.ru; +Cc: 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.

you're thinking of something like:

 $my_integer = intval(preg_replace('!\D+!', '', $my_string));

aren't you?

PCRE regular expression finctions are PERL compatible reg. functions 
using PCRE library.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-11-16 07:15 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-26 15:30 data type casting to numbers with intval() or doubleval() imago <imago@imago3d.com>
2001-04-26 15:50 ` Wesley Leonard <marshall@pacdemon.org>
2001-11-16 07:15   ` Papp Gyozo <pgerzson@freestart.hu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox