Есть html файл закодированный в UTF-8. С помощью php создаю узлы, добавляю в DOM и потом сохраняю в новом файле
Вот php файл
PHP:
скопировать код в буфер обмена
<?PHP header("Content-Type: text/html; charset=utf-8"); $htmlDoc = new DOMDocument('1.0', 'utf-8'); $htmlDoc->preserveWhiteSpace = false; $htmlDoc->loadHTMLFile('ux.html'); $root = $htmlDoc->createElement("div"); $root->setAttribute("class", "forums"); $root_child = $htmlDoc->createElement("div"); $imgWrap = $htmlDoc->createElement("div"); $img = $htmlDoc->createElement("img"); $img->setAttribute("src", "../../images/forum/11971542601675001438kuba_Envelope_2.svg_.hi_-288x300.png"); $titleWrap = $htmlDoc->createElement("div"); $titleWrap->setAttribute("style", "width: 95.79081632653062%"); $titleH3 = $htmlDoc->createElement("h3"); $titleH3A = $htmlDoc->createElement("a", "Привет"); $titleP = $htmlDoc->createElement("p", "ку"); $titleH3->appendChild($titleH3A); $titleWrap->appendChild($titleH3); $titleWrap->appendChild($titleP); $imgWrap->appendChild($img); $root_child->appendChild($imgWrap); $root_child->appendChild($titleWrap); $root->appendChild($root_child); $forumHead = $htmlDoc->getElementById("A123456789"); $forum = $htmlDoc->getElementById('scientists_them_wrap_1'); $forum->insertBefore($root, $forumHead); $htmlDoc->saveHTMLFile('newUx.html'); ?>
Затем смотрю файл newUx.html и там получилась какозябра с кириллицей "Головна".
Хотя в исходном файле ux.html все русские буквы отображались нормально. Помогите решить эту проблему с кодировкой, очень нужно(Отредактировано автором: 07 Января, 2014 - 14:39:20)
|