public static function Crawler::xpathLiteral in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::xpathLiteral()
Converts string for XPath expressions.
Escaped characters are: quotes (") and apostrophe (').
Examples: <code> 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') </code>
Parameters
string $s String to be escaped:
Return value
string Converted string
3 calls to Crawler::xpathLiteral()
- Crawler::selectButton in vendor/
symfony/ dom-crawler/ Crawler.php - Selects a button by name or alt value for images.
- 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 793
Class
- Crawler
- Crawler eases navigation of a list of \DOMElement objects.
Namespace
Symfony\Component\DomCrawlerCode
public static function xpathLiteral($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, ', '));
}