Contact Jan Thomas Consulting

September 13, 2007

PHP: Special Characters from database into HTML

Filed under: Programming Techniques — jan @ 12:38 am

Reserved HTML characters such as ampersand (&) and greater than(>) can cause problems if they appear as ordinary text in an HTML document. The browser will mistake these reserved characters for markup. Use the php function htmlentities to convert characters such as & to & if this becomes a problem.

Be aware though, some text such as RSS feeds contain HTML markup for formatting purposes. In this case, htmlentities is NOT recommened.

Character encoding can also lead to display problems. To ensure proper display of special characters, pay attention to the character encoding. UTF-8 is the default character encoding for XML. ISO-8859-1 is more commonly used in HMTL. If you use UTF-8 encoding in the HTML document’s head section, the special characters from XML files and RSS will display properly.

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress