FluentDOM\Xpath::quote PHP Method

quote() public method

Xpath 1 does not have a way to escape quotes, it only allows double quotes in single quoted literals and single quotes in double quoted literals. If both quotes are included in the string, the method will generate a concat() function call.
public quote ( string $string ) : string
$string string
return string
    public function quote($string)
    {
        $string = str_replace("", '', $string);
        $hasSingleQuote = FALSE !== strpos($string, "'");
        if ($hasSingleQuote) {
            $hasDoubleQuote = FALSE !== strpos($string, '"');
            if ($hasDoubleQuote) {
                $result = '';
                preg_match_all('("[^\']*|[^"]+)', $string, $matches);
                foreach ($matches[0] as $part) {
                    $quoteChar = substr($part, 0, 1) === '"' ? "'" : '"';
                    $result .= ", " . $quoteChar . $part . $quoteChar;
                }
                return 'concat(' . substr($result, 2) . ')';
            } else {
                return '"' . $string . '"';
            }
        } else {
            return "'" . $string . "'";
        }
    }