Jump to content

Removing Currency Symbol


new-2-php

Recommended Posts

Hi Guys,

 

As my username suggests I'm new to PHP and I work largely with client side code. I'm in need of your help and hope someone here can kindly provide a solution or point me in the right direction.

 

I'm working with a serverside script and there is the following line of code:

 

<?php echo $order_total ?>

 

When this renders it displays an amount in addition to the currency symbol (i.e. $10) and I need to remove the currency symbol so it only displays the amount. Is it possible to do this through PHP and if so how?

 

I have read articles on ways to potentially achieve (i.e. preg_replace) this but had no luck in implementing them - hence im here! Your assistance and advice would be greatly appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268974-removing-currency-symbol/
Share on other sites

That would be ideal but I need it to display the symbol on the wider site whilst not displaying it in this one area.
You should always be adding things like formatting and currency symbols at the very instant you display them. Otherwise, you run into problems like this. Are you remembering that there may be a comma in these numbers if you format them using number_format? Do you know:

 

$a = "123,456.78";
echo $a * 2;//echoes "246"

You should always be adding things like formatting and currency symbols at the very instant you display them. Otherwise, you run into problems like this. Are you remembering that there may be a comma in these numbers if you format them using number_format? Do you know:

 

$a = "123,456.78";
echo $a * 2;//echoes "246"

 

Exactly - remove it from the original place, and only output it when displaying. If you don't like that you can assign the formatted one to a new var, and use that as your display, then have the original value still intact.

This is the basis of the MVC coding style. You're mixing display logic (adding formatting and currency symbols) in with controller-level logic. If you ever do anything with these prices other than printing them (like adding them or sorting them) you will get the wrong result and not understand why.

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.