Jump to content

preg_replace? string formatting help


triphis

Recommended Posts

Hello :) I have tried to understand this function, but I just do NOT get it.

 

I have tried to look at the copious "format phone numbers" scripts available, but I can't seem to change it to work for what I need.

 

I actually need two forms:

 

First, I have a number like this: 3032 stored in a DB, and I need to format it 30 x 32 (pant sizes lol).

Also, a bit more complicated, I have either 325, or 32500 stored in a DB, and I need it to come out $325.00

 

This is for a little store website I am writing. Nothing in this store in less than $10 or more than $999, so basically, the first 2 or 3 digits will be the dollars.  If the number is 4 digits long (4595) I need it to know to do $45.95    Three digits long would need .00 ADDED (because nothing would be $X.XX)  5 digits would obviously be XXX.XX  and two digits would have .00 ADDED

 

 

Thank you, and if you can even link me to a good resource for this, that would be GREAT!

Link to comment
https://forums.phpfreaks.com/topic/45367-preg_replace-string-formatting-help/
Share on other sites

Thank you frost and thorp :P

 

i will have to edit the price one a bit so that it adds the .00 where necessary, but that works just fine, thanks :) I didn't expect it to be so simple. obviously I am new to this :P

 

dough boy, I was not aware that there is a decimal field o.O  not "int" is it?

 

and I do actually have the size in a varchar field.  I guess I don't really know why I am making it more difficult on myself... I am clearly going to have to rethink my DB structure LOL

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.