Adding up values with $ signs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Adding up values with $ signs

Post by Templeton Peck »

I have a form with text fields where $ amounts get entered.. like say $5 but when it hits the target php file to total and display the amount. If there are any "$" signs used in the text field on the form it comes out blank in the target php file and doesn't total it. Anyway I can fix this so it'll just ignore the $ sign and add the value beside it?

thanks :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If the amounts are always going to be in dollars then just put the dollar sign in the form next to the text field and just take numerical input in the text field. You can also strip the $ sign out before doing the calculations:

Code: Select all

$no_dollar = str_replace('$', '', $with_dollar);
and put it back when you're finished.

Mac
Post Reply