У меня есть файл PHP, который я использую для создания HTML-файла. Это процесс:Как читать строку PHP как HTML
$document = new DomDocument;
$document->preserveWhiteSpace = false;
$document->validateOnParse = true;
$document->loadHTML(file_get_contents("http://www.example.com/base.html"));
$testNode = $document->createElement("div", "This is a <br> test");
$document->appendChild($testNode);
$document->saveHTMLFile("output.html");
Это выкладывает файл HTML, содержащий следующий элемент:
<div>This is a <br> test</div>
То есть, <br>
теги преобразуются в <br>
в фактическом HTML. Я попробовал все эти методы для экранирования в строку:
htmlspecialchars("This is a <br> test");
rawurldecode("This is a <br> test");
urldecode("This is a <br> test");
function decodeashtml($str) {
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
return html_entity_decode($str,null,'UTF-8');;
}
decodeashtml("This is a <br> test");
, но все они производят:
This is a <br> test
Что еще я могу сделать, чтобы получить HTML-теги правильно отображаются в виде HTML?
Вы можете 'str_replace' это? Сделайте массив всех необходимых вам значений. Тот же принцип, что и bbcode –
Что такое объект '$ document'? – Inurosen
@Inurosen '$ document = new DomDocument;' –