Category: HTML

Convert to HTML Entities Between Code Tags

If you're ever posting a piece of code on your blog or whatever, you've probably realized that it's a pain to have to convert any special character to its HTML entity. Why not take the pain away and let PHP handle that for you?

I'm using something similar for the comments on this blog. After I read Matthew James Taylor's post about this, I tried to come up with something using a little less code.

There really isn't a foolproof method to pull this off, and I have been told that traversing the code using the DOM would be better, but this function (as ugly as it is) actually works quite well if you have a proper HTML structure with valid code.
It checks for any <code> and <pre> tags and converts any special characters inside them to there respective HTML entity. It even accounts for nested <code> and <pre> tags, as well as any attributes you give them.


HTML Sandbox

HTML Sandbox

I've always got ideas running through my head of how to code something, or how something might look. But sometimes I don't feel like going through the trouble of making a new file and filling it with a proper HTML structure just to test a piece of code out real quick. That's why I created this HTML Sandbox page to test out my code.

Features

  • Choose your own DOCTYPE
  • Enable syntax highlighting code editor
  • Paste in code snippets to save time
  • Hide form to see just your content

Check it Out!


Creating & Sending an HTML Email with a Dynamic PDF Attachment

This tutorial will explain how to get the data from a submitted form, create a PDF from that data, and then attach that PDF to an HTML email and finally send it. We will be using dompdf for the PDF generation, and Swift Mailer for sending the email.