Answer the question
In order to leave comments, you need to log in
Why doesn't htmlspecialchars work in DOM context?
I need to insert an inscription in the "tag" containing double quotes "
, but nothing changes. If you simply display a string on the screen and open the source code of the page, then they appear &qout;
, but XML tags are not inserted in this form.
$testTag = $testXML->createElement('test-tag', htmlspecialchars($testString, ENT_XML1 | ENT_QUOTES));
createElement
. But it is inserted all the same with quotation marks. <?php
$testString = 'проверка "тест"';
$testXML = new DOMDocument('1.0', 'utf-8');
$testXML->formatOutput = true;
$testXML->preserveWhiteSpace = false;
$testTag = $testXML->createElement('test-tag', htmlspecialchars($testString, ENT_XML1 | ENT_QUOTES));
$testXML->appendChild($testTag);
// МНОГО ДРУГИХ ВСТАВОК ТЕГОВ
$testXML->save('test.xml');
проверка "тест"
htmlspecialchars()
. Source:<?php
$testString = 'проверка "тест"';
$tshsc = htmlspecialchars($testString, ENT_XML1 | ENT_QUOTES);
$testXML = new DOMDocument('1.0', 'utf-8');
$testXML->formatOutput = true;
$testXML->preserveWhiteSpace = false;
$testTag = $testXML->createElement('test-tag', htmlspecialchars($tshsc, ENT_XML1 | ENT_QUOTES));
$testXML->appendChild($testTag);
// МНОГО ДРУГИХ ВСТАВОК ТЕГОВ
$testXML->save('test.xml');
&
and breaks everything. I did not find how to disable this conversion! проверка &quot;тест&quot;
Answer the question
In order to leave comments, you need to log in
To get a string, use DOMDocument::saveHTML
not DOMDocument::saveXML
. And htmlspecialchars is not needed there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question