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 "" ...>
$href2->setAttribute("PostTitle", html_entity_decode($Title));
setAttribute()默认情况下进行转义,因此如果字符串已转义,则可能需要使用html\u entity\u decode()
<... PostTitle="Sssa "" ...>
$href2->setAttribute("PostTitle", html_entity_decode($Title));
就这么做吧:
$Title = str_replace("-==single-quote==--", ' " ',$Title);
$Title = str_replace('-==double-quote==--', ' " ',$Title);
您将有xml格式的“
。这实际上是可行的,但是,哦,天哪,默认情况下他们有编码??英雄联盟(相关)没有解决方案正常工作。面临实体相关问题。