Displaying specific characters in a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Displaying specific characters in a string

Post 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?
Last edited by DudeBori82 on Thu Dec 09, 2004 4:15 pm, edited 1 time in total.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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]()
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Post by DudeBori82 »

Do I use that with echo? or use them on the variable and then print them out.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Post by DudeBori82 »

Will stripslashes() remove all the slashes, or just the un-wanted ones?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
Post Reply