下面的代碼:的SimpleXMLElement將不保存可讀格式良好的文件
for($i = 0; $i < count(array_values($resources['titles'])); $i++){
//var_dump($key);
$ad = $xml->addChild('ad');
$ad->addChild('title', htmlentities(htmlspecialchars(substr($resources['titles'][$i], 0, 70))));
$ad->addChild('text', 'Текст текст');
$ad->addChild('price', htmlentities($resources['prices'][$i]));
//file_put_contents('test.txt',$resources['titles'][$i]."\n", FILE_APPEND);
}
$xml->asXML($this->_xmlOutput);
它保存所有的數據不錯,但XML文件格式不順利和西里爾符號(那裏有很多人的)變成&#x447(這是什麼代碼?)。另外文件保存爲ansi,而不是utf-8。所以問題是 - 如何正確地創建格式良好且可讀的(帶西里爾符號)XML文檔?
'substr'對UTF-8字符串無法正常工作。 –
但西里爾和格式化最新錯誤。我無法得到它。也許有辦法強制轉換爲UTF-8? – user3416803