Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Function to escape single and double quotes in XPath queries using PHP
<?php
function xpathEscape($query,$default_delim = '"')
{
if((strpos($query,'\'') !== FALSE) ||
(strpos($query,'"') !== FALSE))
{
$quotechars = array('\'','"');
$parts = array();
$current_part = '';
foreach(str_split($query) as $character)
{
if(in_array($character,$quotechars))
{
$parts[] = '\''.$current_part.'\'';
if($character == '\'')
$parts[] = '"'.$character.'"';
else
$parts[] = '\''.$character.'\'';
$current_part = '';
}
else
$current_part .= $character;
}
if($current_part)
$parts[] = '\''.$current_part.'\'';
$ret = 'concat('.implode(',',$parts).')';
}
else
$ret = $default_delim.$query.$default_delim;
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.