Re: [PHP] Quick question on data formatting
At 12:30 AM -0500 11/29/07, Robert Cummings wrote: On Wed, 2007-11-28 at 22:19 -0700, Jon Westcot wrote: $123,456.78 becomes 123456.78 $24,680 becomes 24680 1234B becomes 1234 $number = ereg_replace( '[^[:digit:].]', '' ); Cheers, Rob. Sweet. Another one of those staple functions we all should have (or at least me). Thanks, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Quick question on data formatting
Hi all: Since I'm relatively new to PHP, I'm not familiar with all of the shortcuts and efficient ways one could write a routine that handles converting data from one format into another, so I thought I'd ask here for recommendations on how to solve one particular issue I've got. I'm viewing this as a learning experience for me. I've got some text fields coming in that need to be added to a table as numeric fields. In particular, I've got to process dollar amounts that appear with dollar signs and commas into their strictly numeric forms. For example: $123,456.78 becomes 123456.78 $24,680 becomes 24680 1234B becomes 1234 (That last example is an actual example of something I saw in the data file; I can only assume that the user wanted 1234, as that's the closest value I can assume from what was typed in.) What is the fastest, most efficient way to perform these conversions? I'm coming at PHP from old school experience where I'd normally read through the text character by character and return a value built from only the characters I have declared as acceptable (i.e., 0-9 and . and possibly a -), but I've got to believe that there's some technique -- or possibly a deeply buried function -- available to me now that would be faster and easier to implement. Any help you can provide will, as always, be greatly appreciated! Thanks, Jon
Re: [PHP] Quick question on data formatting
On Wed, 2007-11-28 at 22:19 -0700, Jon Westcot wrote: Hi all: Since I'm relatively new to PHP, I'm not familiar with all of the shortcuts and efficient ways one could write a routine that handles converting data from one format into another, so I thought I'd ask here for recommendations on how to solve one particular issue I've got. I'm viewing this as a learning experience for me. I've got some text fields coming in that need to be added to a table as numeric fields. In particular, I've got to process dollar amounts that appear with dollar signs and commas into their strictly numeric forms. For example: $123,456.78 becomes 123456.78 $24,680 becomes 24680 1234B becomes 1234 $number = ereg_replace( '[^[:digit:].]', '' ); Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick question on data formatting [SOLVED]
Thanks, Rob! I can see that it's going to be important for me to get familiar with the POSIX regular expressions. Jon - Original Message - On Wed, 2007-11-28 at 22:19 -0700, Jon Westcot wrote: Hi all: Since I'm relatively new to PHP, I'm not familiar with all of the shortcuts and efficient ways one could write a routine that handles converting data from one format into another, so I thought I'd ask here for recommendations on how to solve one particular issue I've got. I'm viewing this as a learning experience for me. I've got some text fields coming in that need to be added to a table as numeric fields. In particular, I've got to process dollar amounts that appear with dollar signs and commas into their strictly numeric forms. For example: $123,456.78 becomes 123456.78 $24,680 becomes 24680 1234B becomes 1234 $number = ereg_replace( '[^[:digit:].]', '' ); Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick question on data formatting [SOLVED]
On Wed, 2007-11-28 at 22:47 -0700, Jon Westcot wrote: Thanks, Rob! I can see that it's going to be important for me to get familiar with the POSIX regular expressions. You can use the perl versions too. I just got used to the posix versions a long time ago :). BTW, if you didn't notice I forgot the third parameter :) Cheers, Rob. - Original Message - On Wed, 2007-11-28 at 22:19 -0700, Jon Westcot wrote: Hi all: Since I'm relatively new to PHP, I'm not familiar with all of the shortcuts and efficient ways one could write a routine that handles converting data from one format into another, so I thought I'd ask here for recommendations on how to solve one particular issue I've got. I'm viewing this as a learning experience for me. I've got some text fields coming in that need to be added to a table as numeric fields. In particular, I've got to process dollar amounts that appear with dollar signs and commas into their strictly numeric forms. For example: $123,456.78 becomes 123456.78 $24,680 becomes 24680 1234B becomes 1234 $number = ereg_replace( '[^[:digit:].]', '' ); -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php