You are here: Re: Extracting a numerical value with a comma « PHP Programming Language « IT news, forums, messages
Re: Extracting a numerical value with a comma

Posted by David Haynes on 03/10/06 23:43

laredotornado@zipmail.com wrote:
> Hi,
>
> I have a string value, "1,250" (one thousand, two hundred and fifty).
> Is there a PHP function I can apply to this string that will give me
> the value 1250 in a variable? I've tried "intval", but I get a value
> of 1 (one), at least in PHP 4.
>
> Thanks for any help, - Dave
>

<?php
$foo = "1,250";
$bar = intval(str_replace(',', '', $foo) );

printf("foo = %s, bar = %d\n", $foo, $bar);
?>

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация