views:

31

answers:

2

Let's say I have this string:

Hello &, how are you? I'm  fine!

Is there a function that will convert this to:

Hello &, how are you? I'm fine!

Also, why does "'" sometimes show up as: � on sites? What am I missing?

+4  A: 

Yes, htmlspecialchars().

The translations performed are:

  • & (ampersand) becomes &
  • " (double quote) becomes " when ENT_NOQUOTES is not set.
  • ' (single quote) becomes ' only when ENT_QUOTES is set.
  • < (less than) becomes &lt;
  • > (greater than) becomes &gt;
cletus
A: 

To answer your second question, regarding the improper rendering of characters, it has to do with having straight unicode characters in your file. This is usually the result of pasting in from a program that is using unicode characters. When this unicode isn't converted to ASCII or an HTML entity, it won't be rendered properly in the browser as the browser will try to interpret it as something that it is not.

Timothy Armstrong