Jump to content

Archived

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

bluecubic

Trim a comma along with several other characters.

Recommended Posts

I'm trying to trim out several characters.  It's not trimming out the comma, it is trimming the other characters.  Thanks.

Here's what I have now:

echo trim($orders['order_total'], '< > b $ / \ ","');

Share this post


Link to post
Share on other sites
Why the quotes around the comma?

If you just use:
[code]<?php echo trim($orders['order_total'], ' <>b$/\,'); ?>[/code]
Does it work?

Can you post an example of your input and desired output?

Ken

Share this post


Link to post
Share on other sites
I tried to encapsulating the comma in quotes to see if that would work...

Thanks for the quick reply.  That code unfortunately didn't work.  I also just tried
[code]echo trim($orders['order_total'], ',');[/code] and it didn't filter out the comma...

Example:

input:  [code]<b>$1,000.00</b>[/code]

desired output: 1000.00

Thanks.

Share this post


Link to post
Share on other sites
The trim() funtion will only remove character from the beginning or end of a string. You want to look at str_replace():
[code]<?php
$str = '$1,000.00';
echo str_replace(array('$',','),'',$str);
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

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.