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):
http://kushalm.com/the-perils-of-xpath-expressions-specifically-escaping-quotes
I've produced a PHP solution for the general escaping/concatenation problem:
https://gist.github.com/1155973
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
Subscribe
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).
Recent Posts
- RSS is only dead if we let it die
- Kill your index.php
- 18 Things I Wish I Knew 7 Years Ago
- When does automation become coding
- A list of things you can do to afford Mixergy Premium in 2012
- Thanks Louis now here is my dad
- Your templating engine sucks and everything you have ever written is spaghetti code yes you
- Energy for Opportunity website is now live
- Escaping single and double quotes in XPath queries in PHP
- The reason that outsourcing software is so difficult