Escaping single and double quotes for use with XPath queries in PHP

19 Aug2011

I've been working with the Basecamp API to plugin our IRC bot that we use for time tracking and I'm astounded to learn that escaping single and/or double quotes for XPath queries in PHP does not have a well documented, best practices solution.

In fact, it seems as though this is not peculiar to PHP. I took a look around and found this excellent article by "Kushal" (s/he doesn't have his full name on his blog):

I've produced a PHP solution for the general escaping/concatenation problem:

Anyone got a better/more elegant solution? I'm always a big fan of code golf :)

This entry was posted on Friday, August 19th, 2011 at 1:35 pm php, recipe, recipes, xml, snippet, snippets, xpath

blog comments powered by Disqus


Subscribe via RSS

Building software in the real world - the Working Software blog

We write about our experiences, ideas and interests in business, software and the business of software. We also sometimes write about our own products (in order to promote them).