Created
July 16, 2010 12:24
-
-
Save drslump/478306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Escapes a string (if needed) using the concat function for its use | |
// in xpath expressions. | |
// Example: | |
// $xpath = '/*[@value=' . escape_string_xpath("this is "foo's\"!") . ']'; | |
// Becomes: | |
// /*[@value=concat('this is "foo', "'", 's"!')] | |
function escape_string_xpath($value) { | |
if (strpos($value, '"') === false) { | |
return '"' . $value . '"'; | |
} else if (strpos($value, "'") === false) { | |
return "'" . $value . "'"; | |
} | |
return 'concat("' . str_replace('"', '", \'"\', "', $value) . '")'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment