Jump to content


Photo

Trim a comma along with several other characters.


  • Please log in to reply
4 replies to this topic

#1 bluecubic

bluecubic
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 July 2006 - 08:59 PM

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 $ / \ ","');

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 09:04 PM

Why the quotes around the comma?

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

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

Ken

#3 bluecubic

bluecubic
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 July 2006 - 09:21 PM

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
echo trim($orders['order_total'], ',');
and it didn't filter out the comma...

Example:

input: 
<b>$1,000.00</b>

desired output: 1000.00

Thanks.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 09:27 PM

The trim() funtion will only remove character from the beginning or end of a string. You want to look at str_replace():
<?php
$str = '$1,000.00';
echo str_replace(array('$',','),'',$str);
?>

Ken

#5 bluecubic

bluecubic
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 July 2006 - 09:38 PM

Thanks Ken!

Worked great.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users