Skip to content

Commit a4e3ebf

Browse files
committed
[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.
1 parent a27cbd9 commit a4e3ebf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,15 @@ public function html()
499499

500500
$html = '';
501501
foreach ($this->getNode(0)->childNodes as $child) {
502-
$html .= $child->ownerDocument->saveHTML($child);
502+
if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
503+
// node parameter was added to the saveHTML() method in PHP 5.3.6
504+
// @see http://php.net/manual/en/domdocument.savehtml.php
505+
$html .= $child->ownerDocument->saveHTML($child);
506+
} else {
507+
$document = new \DOMDocument('1.0', 'UTF-8');
508+
$document->appendChild($document->importNode($child, true));
509+
$html .= rtrim($document->saveHTML());
510+
}
503511
}
504512

505513
return $html;

0 commit comments

Comments
 (0)