Simple PHP Tool for Converting Character to HTML entities

I have been using MobilePress to mobilize my blog since its inception.
I discovered when HTML source codes are included in a blog post, the code is parsed as HTML when the article is viewed on mobile but is ok when viewed on PC. Mind you, I do wrap the code using a syntax highlighter to prevent the code from being parsed.

The problem was as a result of the absent of the syntax highlighter component (JavaScript and CSS files) in MobilePress.

Adding the component to the header of MobilePress version of my blog would fix the problem, but I refuse to go that route because I don’t want to increase the number of HTTP Request on mobile.

According to Yahoo’s performance rule:

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.

To prevent source codes from being parsed as HTML, I have to first convert the code to HTML entities before including it in a post.

To make the conversion of characters / HTML code to entities painless, I built a simple conversion tool powered by PHP’s htmlentities & htmlspecialchars function and CodeMirror (a versatile text editor implemented in JavaScript for the browser that make code presentation pretty).
More on the tool shortly…

Difference between htmlentities() and htmlspecialchars()

It worth noting the difference between these two functions.

htmlspecialchars function only convert special characters that has significance in HTML to entities. While htmlentities will look for all possible ways to convert all applicable characters to HTML entities.
Thus, the former perform basic conversion while that of the latter is aggressive.

References

Convert character to HTML Entities Tool

Want to see how this tool work? here is the demo.

See the lite version of the tool without codemirror in action below.

[phpcode file=”character-html-entities”]

The code of this tool is available freely at my Github Repo.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address