| @@ 147-169 (lines=23) @@ | ||
| 144 | } |
|
| 145 | } |
|
| 146 | ||
| 147 | if ($documentFound === false) { |
|
| 148 | ||
| 149 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 150 | $xmlHackUsed = false; |
|
| 151 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 152 | if (\stripos('<?xml', $xml) !== 0) { |
|
| 153 | $xmlHackUsed = true; |
|
| 154 | $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml; |
|
| 155 | } |
|
| 156 | ||
| 157 | $this->document->loadXML($xml, $optionsXml); |
|
| 158 | ||
| 159 | // remove the "xml-encoding" hack |
|
| 160 | if ($xmlHackUsed) { |
|
| 161 | foreach ($this->document->childNodes as $child) { |
|
| 162 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 163 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 164 | $this->document->removeChild($child); |
|
| 165 | ||
| 166 | break; |
|
| 167 | } |
|
| 168 | } |
|
| 169 | } |
|
| 170 | } |
|
| 171 | ||
| 172 | // set encoding |
|
| @@ 354-376 (lines=23) @@ | ||
| 351 | } |
|
| 352 | } |
|
| 353 | ||
| 354 | if ($documentFound === false) { |
|
| 355 | ||
| 356 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 357 | $xmlHackUsed = false; |
|
| 358 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 359 | if (\stripos('<?xml', $html) !== 0) { |
|
| 360 | $xmlHackUsed = true; |
|
| 361 | $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html; |
|
| 362 | } |
|
| 363 | ||
| 364 | $this->document->loadHTML($html, $optionsXml); |
|
| 365 | ||
| 366 | // remove the "xml-encoding" hack |
|
| 367 | if ($xmlHackUsed) { |
|
| 368 | foreach ($this->document->childNodes as $child) { |
|
| 369 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 370 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 371 | $this->document->removeChild($child); |
|
| 372 | ||
| 373 | break; |
|
| 374 | } |
|
| 375 | } |
|
| 376 | } |
|
| 377 | } |
|
| 378 | ||
| 379 | // set encoding |
|