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
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"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.