Samveen's Blog

29th April 2011

PHP Quote Escaping Stupidity

I use the excellently minimalistic hlscript by Brennan Underwood for blogging. However, due to it's minimalism, it lacks a blog entry creation UI. All entries have to be written in or pushed to the server via the terminal. Additionally I lose the ability to preview the post.

So I decided to hack up a small entry creator script that allows me to preview and then submit each post. Nothing very polished nor integrated into hlscript, just a stand alone script that can create a file in the entry format used by hlscript.

While writing and testing this script, I found out two important things. First, irritatingly, PHP escaped all quotes automatically and second, more irritatingly although off topic, I've lost all touch with PHP and web coding, . This auto-escaping of quotes leads to a doubling of backslashes every time I press preview. A quick search gives me the solution as explained here, with a nice example use case here. Essentially

if(get_magic_quotes_gpc()) {
    $value = stripslashes($value);