473,479 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Extracting a numerical value with a comma

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

Mar 10 '06 #1
1 1639
la***********@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-

Mar 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1931
by: For example John Smith | last post by:
My source file contains numerical information shaped like this: 32,567,90 32,689,78 et cetera If I use (longint)$numstr I get 32 as value (logically). How can I convince php to ignore the...
2
2967
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
5
2931
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
2
2627
by: Dirtyweeker | last post by:
Hi, I have a database which records fitness test results of pupils. There are the usual name fields and then a series of fields holding results, e.g. field BP1 and field BP2; each of these...
13
3711
by: Randy | last post by:
Is there any way to do this? I've tried tellg() followed by seekg(), inserting the stream buffer to an ostringstream (ala os << is.rdbuf()), read(), and having no luck. The problem is, all of...
16
10938
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some...
2
1566
by: Ian Eagland | last post by:
Hi I am just starting on Visual C (2003) from a VB background. I find it easier to learn by actually programming. I have fallen over at the first hurdle. How do you extract a numerical value...
4
2284
by: Charlie Hoffpauir | last post by:
How do I extract a surname from a name field in which the name is in the form: <surname, given names>. My first though was to run an update query, but I can't find the function that will give me...
22
3198
by: sivadhanekula | last post by:
Hello Everyone A quick and direct question: I need a C/C++ program to extract the data from the database and the output should be in CSV "Comma Separated Value" format. Briefly: I will be given a...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.