473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Comma separated numerical values

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 , in these strings ?
Probably in the manual, but I could not find an entry for this. Don't know
how to call this problem.
TIA
Pjotr
Jul 17 '05 #1
3 1928
Pjotr,

One way would be to strip them out like so:

$newNum = preg_replace('/,/', '', $origNum);

Then do the rest using $newNum.

HTH

jg
"For example John Smith" <zp*******@xz4all.nl> wrote in message
news:40***********************@news.sunsite.dk...
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 , in these strings ?
Probably in the manual, but I could not find an entry for this. Don't know
how to call this problem.
TIA
Pjotr

Jul 17 '05 #2
jerrygarciuh wrote:
Pjotr,

One way would be to strip them out like so:

$newNum = preg_replace('/,/', '', $origNum);

Then do the rest using $newNum.

HTH


Is not "str_replace" faster?
$newNum = str_replace(',','',$origNum);
Jul 17 '05 #3
Westcoast Sheri wrote:
jerrygarciuh wrote:
Pjotr,

One way would be to strip them out like so:

$newNum = preg_replace('/,/', '', $origNum);

Then do the rest using $newNum.

HTH


Is not "str_replace" faster?
$newNum = str_replace(',','',$origNum);


Thanks guys, both options work, and to satisfy your curiosity:
Using str_replace and preg_replace -at least in my example- took the same
amount of time.
I ran each about ten times, and all execution times are in the same range.
In this example the replace is called about 27k times, a reasonably
significant amount to judge execution speed I'd say.
I used a stopwatch based on microtime (), the script runs on a P3-500Mhz,
LAMP.
I'll be using str_replace from here, as I am much less comfortable with
regexp (yet).

Actually I would have guessed PHP has a function specifically for
number-(un)formatting, but hey, this works fine!
Thanks again!
Pjotr
Jul 17 '05 #4

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

Similar topics

7
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the...
1
by: Craig Keightley | last post by:
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 ...
11
by: Craig Keightley | last post by:
I have a mysql database with a list of companies who supply specific products tblSuppliers (simplified) sID | sName | goodsRefs 1 | comp name | 1,2,3,4,5 2 | company 2 | 2,4
9
by: phillip.s.powell | last post by:
Ok, you have three tables. You're supposed to be able to not only sort (ORDER BY) according to a_name, no problem, but you must also have the ability to sort (ORDER BY) the relationship between...
3
by: mahe23 | last post by:
All, How do One convert a comma separated column from a text file into rows in oracle. I have a scenario where the list of comma separated values changes dynamically. It is like: abc, ttt,...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
4
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
3
by: nigel | last post by:
Hi, I'm using VBA to export data from a table direct to a CSV file DoCmd.TransferText acExportDelim, , "ExportTable", filePath this produced a file with COMMA separated values,...
4
by: flavourofbru | last post by:
Hi, In the datagridview control, one of my column has multiple values separated by a comma Is there a way to get individaual values which are separated by a comma from that particular cells? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.