Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Created August 19, 2011 03:34
Show Gist options
  • Select an option

  • Save iaindooley/1155973 to your computer and use it in GitHub Desktop.

Select an option

Save iaindooley/1155973 to your computer and use it in GitHub Desktop.

Revisions

  1. iaindooley revised this gist Aug 21, 2011. No changes.
  2. iaindooley renamed this gist Aug 21, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. iaindooley revised this gist Aug 19, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generic_concat.php
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ function xpathEscape($query,$default_delim = '"')
    }

    if($current_part)
    $parts[] = $current_part;
    $parts[] = '\''.$current_part.'\'';

    $ret = 'concat('.implode(',',$parts).')';
    }
  4. iaindooley revised this gist Aug 19, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generic_concat.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <?php
    function genericXpathQuoteConcatenation($query,$default_delim = '"')
    function xpathEscape($query,$default_delim = '"')
    {

    if((strpos($query,'\'') !== FALSE) ||
  5. iaindooley created this gist Aug 19, 2011.
    40 changes: 40 additions & 0 deletions generic_concat.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <?php
    function genericXpathQuoteConcatenation($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;
    }