Page 1 of 1

Displaying specific characters in a string

Posted: Thu Dec 09, 2004 3:52 pm
by DudeBori82
How do I display a ' or a " in a string? It usually comes out '' or \" when it echos. Also, I use

Code: Select all

<?php
echo round($shipping, 2);
?>
to round to the nearest two decimal places, but when it's a whole number, it doesn't echo any decimal places. I would like it to display ".00" if its a whole number. How can I do that?

Posted: Thu Dec 09, 2004 3:59 pm
by protokol
If you're getting a ' or " with '' or \" then use [php_man]stripslashes[/php_man](). For getting decimal places, try [php_man]sprintf[/php_man]() or [php_man]number_format[/php_man]()

Posted: Thu Dec 09, 2004 4:32 pm
by DudeBori82
Do I use that with echo? or use them on the variable and then print them out.

Posted: Thu Dec 09, 2004 5:28 pm
by Chris Corbyn
You COULD put it inside echo() but it's harder to see whats going on. Just execute the function on the variable to create a new variable $roundedUp or something, then echo that variable back out

Posted: Fri Dec 10, 2004 7:08 am
by DudeBori82
Will stripslashes() remove all the slashes, or just the un-wanted ones?

Posted: Fri Dec 10, 2004 7:30 am
by protokol
All the slashes that are escaping other characters. So for example if you have \\, then you'll end up with \ still in the string.