Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP XML DOM不需要转义字符,我无法编写&;qnot;_Php_Xml_Dom_Escaping_Special Characters - Fatal编程技术网

PHP XML DOM不需要转义字符,我无法编写&;qnot;

PHP XML DOM不需要转义字符,我无法编写&;qnot;,php,xml,dom,escaping,special-characters,Php,Xml,Dom,Escaping,Special Characters,我跟你有点问题 $xml2 = new DOMDocument; $xml2->load($FilenamePost."/".$FilenameOfThePost.'.xml'); /* filename.xml */ $xpath2 = new DOMXPath($xml2); $hrefs2 = $xpath2->evaluate("/page"); $Title = str_replace("-==single-quote==--"," " ",$Titl

我跟你有点问题

$xml2 = new DOMDocument;
$xml2->load($FilenamePost."/".$FilenameOfThePost.'.xml');

/* filename.xml */
$xpath2 = new DOMXPath($xml2);
$hrefs2 = $xpath2->evaluate("/page");

$Title = str_replace("-==single-quote==--"," " ",$Title);
$Title = str_replace('-==double-quote==--',' " ',$Title);

$Title = str_replace('"',' " ',$Title);

$Title = "Sssa "";

$href2 = $hrefs2->item(0);
$href2->setAttribute("PostTitle",$Title);

$xml2->save($FilenamePost."/".$FilenameOfThePost.'.xml');

/*
And when i try to write 
" 
in my xml, it keeps showing 
"
*/
这是为什么???我找不到逻辑解释…

您必须直接编写
,DomDocument负责对其进行转义

$Title = "Sssa &";
...
...->setAttribute("PostTitle", $Title);
保存时,PostTitle属性将正确转义:

<... PostTitle="Sssa &quot;" ...>
$href2->setAttribute("PostTitle", html_entity_decode($Title));
setAttribute()默认情况下进行转义,因此如果字符串已转义,则可能需要使用html\u entity\u decode()

<... PostTitle="Sssa &quot;" ...>
$href2->setAttribute("PostTitle", html_entity_decode($Title));
就这么做吧:

$Title = str_replace("-==single-quote==--", ' " ',$Title);
$Title = str_replace('-==double-quote==--', ' " ',$Title);

您将有xml格式的

这实际上是可行的,但是,哦,天哪,默认情况下他们有编码??英雄联盟(相关)没有解决方案正常工作。面临实体相关问题。