| @@ 306-328 (lines=23) @@ | ||
| 303 | } |
|
| 304 | } |
|
| 305 | ||
| 306 | if ($documentFound === false) { |
|
| 307 | ||
| 308 | // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251 |
|
| 309 | $xmlHackUsed = false; |
|
| 310 | if (\stripos('<?xml', $html) !== 0) { |
|
| 311 | $xmlHackUsed = true; |
|
| 312 | $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html; |
|
| 313 | } |
|
| 314 | ||
| 315 | $this->document->loadHTML($html, $optionsXml); |
|
| 316 | ||
| 317 | // remove the "xml-encoding" hack |
|
| 318 | if ($xmlHackUsed) { |
|
| 319 | foreach ($this->document->childNodes as $child) { |
|
| 320 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 321 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 322 | $this->document->removeChild($child); |
|
| 323 | ||
| 324 | break; |
|
| 325 | } |
|
| 326 | } |
|
| 327 | } |
|
| 328 | } |
|
| 329 | ||
| 330 | // set encoding |
|
| 331 | $this->document->encoding = $this->getEncoding(); |
|
| @@ 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 | if (\stripos('<?xml', $xml) !== 0) { |
|
| 152 | $xmlHackUsed = true; |
|
| 153 | $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml; |
|
| 154 | } |
|
| 155 | ||
| 156 | $this->document->loadXML($xml, $optionsXml); |
|
| 157 | ||
| 158 | // remove the "xml-encoding" hack |
|
| 159 | if ($xmlHackUsed) { |
|
| 160 | foreach ($this->document->childNodes as $child) { |
|
| 161 | if ($child->nodeType === \XML_PI_NODE) { |
|
| 162 | /** @noinspection UnusedFunctionResultInspection */ |
|
| 163 | $this->document->removeChild($child); |
|
| 164 | ||
| 165 | break; |
|
| 166 | } |
|
| 167 | } |
|
| 168 | } |
|
| 169 | } |
|
| 170 | ||
| 171 | // set encoding |
|
| 172 | $this->document->encoding = $this->getEncoding(); |
|