| @@ 434-459 (lines=26) @@ | ||
| 431 | } |
|
| 432 | } |
|
| 433 | ||
| 434 | if ($documentFound === false) { |
|
| 435 | ||
| 436 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 437 | $xmlHackUsed = false; |
|
| 438 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 439 | if (\stripos('<?xml', $html) !== 0) { |
|
| 440 | $xmlHackUsed = true; |
|
| 441 | $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html; |
|
| 442 | } |
|
| 443 | ||
| 444 | if ($html !== '') { |
|
| 445 | $this->document->loadHTML($html, $optionsXml); |
|
| 446 | } |
|
| 447 | ||
| 448 | // remove the "xml-encoding" hack |
|
| 449 | if ($xmlHackUsed) { |
|
| 450 | foreach ($this->document->childNodes as $child) { |
|
| 451 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 452 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 453 | $this->document->removeChild($child); |
|
| 454 | ||
| 455 | break; |
|
| 456 | } |
|
| 457 | } |
|
| 458 | } |
|
| 459 | } |
|
| 460 | ||
| 461 | // set encoding |
|
| 462 | $this->document->encoding = $this->getEncoding(); |
|
| @@ 152-175 (lines=24) @@ | ||
| 149 | } |
|
| 150 | } |
|
| 151 | ||
| 152 | if ($documentFound === false) { |
|
| 153 | ||
| 154 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 155 | $xmlHackUsed = false; |
|
| 156 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 157 | if (\stripos('<?xml', $xml) !== 0) { |
|
| 158 | $xmlHackUsed = true; |
|
| 159 | $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml; |
|
| 160 | } |
|
| 161 | ||
| 162 | $this->document->loadXML($xml, $optionsXml); |
|
| 163 | ||
| 164 | // remove the "xml-encoding" hack |
|
| 165 | if ($xmlHackUsed) { |
|
| 166 | foreach ($this->document->childNodes as $child) { |
|
| 167 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 168 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 169 | $this->document->removeChild($child); |
|
| 170 | ||
| 171 | break; |
|
| 172 | } |
|
| 173 | } |
|
| 174 | } |
|
| 175 | } |
|
| 176 | ||
| 177 | // set encoding |
|
| 178 | $this->document->encoding = $this->getEncoding(); |
|