Answer the question
In order to leave comments, you need to log in
How to replace $str = new SimpleXMLElement($str) in PHP 5.3?
The code $str = new SimpleXMLElement($str) throws an error, the string contains:
<div class="path">
<a href="http://site/" class="start">Главная</a>
<span>–</span>
<a href="http://site/about.html">О нас</a>
<span>–</span>
Схемы этажей
</div>
Answer the question
In order to leave comments, you need to log in
helped to turn on the display of errors, an invalid character is white and an incorrect encoding, the output again had to be in a different encoding
$str = mb_convert_encoding($str, "UTF-8", "windows-1251");
$str = str_replace("&ndash", '-', $str);
// ОШибочки
libxml_use_internal_errors(true);
$xml = simplexml_load_string($str);
if (false === $xml) {
$errors = libxml_get_errors();
echo 'Errors are ' . var_export($errors, true);
throw new \Exception('invalid XML');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question