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 3 1925
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
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);
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
...
|
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
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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?
...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |