In my PHP script, I use XPATH to search for nodes for text. Everything works smoothly - except when I'm looking for a word with an apostrophe.
basically my code is as follows
$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 of the above codes work fine - I can search for strings inside nodes, and I get the correct matches.
However, if the node looks like this: <line number="23">Shall I compare thee to a summer day?</line>
and I'm looking for a summer day ... I get errors in the above line $nodes . What else if I search for "... summer" (no apos), the above line does not match. The only way to return the above string is to search for "... summer", which will include daylight saving time.
I tried stripslashes, addlashes, tohellwithslashes, htmlspecialchars, but nothing works. Also, according to Google, in XPATH 1.0 (which I have to use because it's PHP), I NEVER can escape the apostrophe. Really?
So, I turn to the geniuses here, someone MUST deal with an XML file that they needed to go from XPATH to PHP, which had an apostrap! If XPATH cannot do this, what can I do in PHP to get XPATH to return this node?