Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Created August 21, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaindooley/1161355 to your computer and use it in GitHub Desktop.
Save iaindooley/1161355 to your computer and use it in GitHub Desktop.
xpathEscape() inputs and expected output
<?php
require('xpath_escape.php');
$strings = array('i think therefore i am',
'the pimp\'s "main squeeze" was talkin\' jive');
foreach($strings as $query)
echo xpathEscape($query).PHP_EOL;
/**
* EXPECTED OUTPUT:
* "i think therefore i am"
* concat('the pimp',"'",'s ','"','main squeeze','"',' was talkin',"'",' jive')
*
* EXAMPLE USAGE
* $xml->xpath('//node[subnode='.xpathEscape($string).']');
*
* NOTE: because if no single or double quotes are present the original query is returned
* wrapped in the delimeter (default " but you can pass it in as an optional argument
* to xpathEscape()) you do not include string delimeters in the xpath expression when
* calling the escape function
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment