| @@ 151-173 (lines=23) @@ | ||
| 148 | } |
|
| 149 | } |
|
| 150 | ||
| 151 | if ($documentFound === false) { |
|
| 152 | ||
| 153 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 154 | $xmlHackUsed = false; |
|
| 155 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 156 | if (\stripos('<?xml', $xml) !== 0) { |
|
| 157 | $xmlHackUsed = true; |
|
| 158 | $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml; |
|
| 159 | } |
|
| 160 | ||
| 161 | $this->document->loadXML($xml, $optionsXml); |
|
| 162 | ||
| 163 | // remove the "xml-encoding" hack |
|
| 164 | if ($xmlHackUsed) { |
|
| 165 | foreach ($this->document->childNodes as $child) { |
|
| 166 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 167 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 168 | $this->document->removeChild($child); |
|
| 169 | ||
| 170 | break; |
|
| 171 | } |
|
| 172 | } |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||
| 176 | // set encoding |
|
| @@ 373-395 (lines=23) @@ | ||
| 370 | } |
|
| 371 | } |
|
| 372 | ||
| 373 | if ($documentFound === false) { |
|
| 374 | ||
| 375 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 376 | $xmlHackUsed = false; |
|
| 377 | /** @noinspection StringFragmentMisplacedInspection */ |
|
| 378 | if (\stripos('<?xml', $html) !== 0) { |
|
| 379 | $xmlHackUsed = true; |
|
| 380 | $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html; |
|
| 381 | } |
|
| 382 | ||
| 383 | $this->document->loadHTML($html, $optionsXml); |
|
| 384 | ||
| 385 | // remove the "xml-encoding" hack |
|
| 386 | if ($xmlHackUsed) { |
|
| 387 | foreach ($this->document->childNodes as $child) { |
|
| 388 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 389 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 390 | $this->document->removeChild($child); |
|
| 391 | ||
| 392 | break; |
|
| 393 | } |
|
| 394 | } |
|
| 395 | } |
|
| 396 | } |
|
| 397 | ||
| 398 | // set encoding |
|