In my PHP script, I'm using XPATH to search nodes for text. Everything works swimmingly -except - when I search for a word with an apostrophe.
basically my code looks like this
$keyword = $_GET['keyword'];
...snip...
$xml = simplexml_load_file($data);
$search = strtolower($keyword);
$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$lower = "abcdefghijklmnopqrstuvwxyz";
$nodes = $xml-xpath("//line[contains(translate(text(),'$upper','$lower'),'$search')]");
again, all the above code works great - I can search for strings inside nodes and I get the correct matches back.
However, if a node looks like this:
<line number="23">Shall I compare thee to a summer's day?</line>
and I search for summer's day...I get errors on the above $nodes
line. What's more, if I search for "...summers" (no apos) the above line does not match. The only way to get the above line to return would be a search for "...summer" - which would include summer's.
I've tried stripslashes, addslashes, tohellwithslashes, htmlspecialchars but nothing works. Also, According to Google, in XPATH 1.0 (which I'm forced to use since this is PHP) I will NEVER be able to escape an apostrophe. Seriously?
So I turn to the geniuses here, someone MUST have had to deal with an XML file that they needed to traverse with XPATH in PHP that had an apostraphe! If XPATH can't do this, what can I do in PHP to get XPATH to return this node?