function Crawler::xpathLiteral
Converts string for XPath expressions.
Escaped characters are: quotes (") and apostrophe (').
Examples:
echo Crawler::xpathLiteral('foo " bar'); //prints 'foo " bar'
echo Crawler::xpathLiteral("foo ' bar"); //prints "foo ' bar"
echo Crawler::xpathLiteral('a\'b"c'); //prints concat('a', "'", 'b"c')
4 calls to Crawler::xpathLiteral()
- Crawler::selectButton in vendor/
symfony/ dom-crawler/ Crawler.php - Selects a button by name or alt value for images.
- Crawler::selectImage in vendor/
symfony/ dom-crawler/ Crawler.php - Selects images by alt value.
- Crawler::selectLink in vendor/
symfony/ dom-crawler/ Crawler.php - Selects links by name or alt value for clickable images.
- Form::initialize in vendor/
symfony/ dom-crawler/ Form.php - Adds form elements related to this form.
File
-
vendor/
symfony/ dom-crawler/ Crawler.php, line 894
Class
- Crawler
- Crawler eases navigation of a list of \DOMNode objects.
Namespace
Symfony\Component\DomCrawlerCode
public static function xpathLiteral(string $s) : string {
if (!str_contains($s, "'")) {
return \sprintf("'%s'", $s);
}
if (!str_contains($s, '"')) {
return \sprintf('"%s"', $s);
}
$string = $s;
$parts = [];
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));
}