PHP has Xpath 1.0, if you have a string with double and single quotes, the workaround uses the Xpath function concat(). A helper function can decide when to use what. Example / Use:
xpath_string('I lowe "double" quotes.');
// xpath: 'I lowe "double" quotes.'
xpath_string('It\ my life.');
// xpath: "It my life."
xpath_string('Say: "Hello\'sen".');
// xpath: concat('Say: "Hello', "'", "'sen".')
Auxiliary function:
/**
* xpath string handling xpath 1.0 "quoting"
*
* @param string $input
* @return string
*/
function xpath_string($input) {
if (false === strpos($input, "'")) {
return "'$input'";
}
if (false === strpos($input, '"')) {
return "\"$input\"";
}
return "concat('" . strtr($input, array("'" => '\', "\'", \'')) . "')";
}
source
share