I have read much of the PHP function manual, looked through these forums, and apologize if the answer already exists here, but as an avid PHP prorgammer I cannot seem to find the answer to this simple question.
On my website I store all numeric data (totals, monthly rent, etc) in varchar types so that users can enter periods, dollar signs, commas, etc. Now I need to create some reports that uses the numeric (actually varchar/character) data in calculations. How do I strip out the non-numeric positions? The best I have thought up is emploding the thing at the non-numeric characters and then piecing the variables back together.
Example:
how do I get $3,340.21 into --> 3340.21
I know the trim function could probably rid me of the dollar sign, but how do you strip specfic characters out that are within a string.
A million thanks to anyone who can help.
Adam
Stripping data from a varchar string
Moderator: General Moderators
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
str_replace() is your friend.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact: