Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Escaper.php

function Escaper::escapeLiteral

Escapes the string as a XPath literal.

Parameters

string $s:

Return value

string

File

vendor/behat/mink/src/Selector/Xpath/Escaper.php, line 27

Class

Escaper
XPath escaper.

Namespace

Behat\Mink\Selector\Xpath

Code

public function escapeLiteral(string $s) {
    if (false === strpos($s, "'")) {
        return sprintf("'%s'", $s);
    }
    if (false === strpos($s, '"')) {
        return sprintf('"%s"', $s);
    }
    $string = $s;
    $parts = array();
    while (true) {
        if (false !== ($pos = strpos($string, "'"))) {
            $parts[] = sprintf("'%s'", substr($string, 0, $pos));
            $parts[] = "\"'\"";
            $string = substr($string, $pos + 1);
        }
        else {
            $parts[] = "'{$string}'";
            break;
        }
    }
    return sprintf('concat(%s)', implode(',', $parts));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal