Help Help A Monster Has Eaten My Entities!

Jun 26, 2015

A tale from the what a maroon department.

In writing the last bit of a new PHP version of this blog (I decided to just redo it with a more modern PHP), I wanted to make sure the editor would properly handle html entities, something the current one isn't all that good at.

Now I set up a VM with Vagrant with the matching versions of things on my DigitalOcean droplet to develop on, and I am using PHPStorm but I don't have a debugger installed. I figured I could dump stuff to the browser, old school. This worked great until I started to test html entities.

I put

test & amp ;

into the editarea (no spaces obviously). Then I dumped it back into the web page from PHP and looked at it with Safari's source view. It showed &.

Say what, why is PHP replacing the entity with its actual character?

So I did some research and found other people had a similar issue. Of course I missed that most of them were using some kind of framework that did tricks but I assumed that PHP must be the root problem.

Did I ever mention I only write PHP once every 5 years or so? So I saw people having similar issues and the confirmation bias brick hit me in the head! Aha, PHP must be the fault.

So I learned about

file_get_contents("php://input");

Now I could see the raw post data. There it is! My entity. PHP sucks! It's eating my entity for sure.

So naturally I posted these facts on stackoverflow. The folks there seemed amused by my reporting the problem which they were sure didn't exist. But I protested, I can see it with my eyes, even without the proverbial goggles-that-do-nothing! Someone asked me if I had not just looked at the browser window which of course would show the interpreted entity.

Of course not, I am not a maroon.

So for grins I looked at the site in Chrome and its source view and lo and behold, there was the entity! Magically.

I looked at again at the same page in Safari and its source view, and there sat a sad lonely &. Stupid Safari! You lied to me.

So now I am all humble pie, a maroon (as in Bugs Bunny) shaded PHP abuser.

My entities are alive, just as they should be. PHP is still an ugly hack, but it does work correctly. It is I who must bear the brunt of stupidly believing my eyes and immediately blaming the language.

The world is again safe for html entities. And I am a maroon.