[DomCrawler] Fixed the Crawler::html() method for PHP versions earlier than 5.3.6.

Node argument was added to the DOMDocument::saveHTML() in PHP 5.3.6. See http://php.net/manual/en/domdocument.savehtml.php.
This commit is contained in:
Jakub Zalas 2013-05-11 21:34:40 +01:00
parent a27cbd9f45
commit a4e3ebf385
1 changed files with 9 additions and 1 deletions

View File

@ -499,7 +499,15 @@ class Crawler extends \SplObjectStorage
$html = '';
foreach ($this->getNode(0)->childNodes as $child) {
$html .= $child->ownerDocument->saveHTML($child);
if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
// node parameter was added to the saveHTML() method in PHP 5.3.6
// @see http://php.net/manual/en/domdocument.savehtml.php
$html .= $child->ownerDocument->saveHTML($child);
} else {
$document = new \DOMDocument('1.0', 'UTF-8');
$document->appendChild($document->importNode($child, true));
$html .= rtrim($document->saveHTML());
}
}
return $html;