PHP XML DOM 不需要的转义字符,我不能写 &qnot;
我有一个问题,
$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
"
*/
这是为什么???我找不到逻辑解释...
i'm having a problem with
$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
"
*/
WHY IS THIS??? I cannot find a logical explication ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只要这样做:
您将拥有 xml 格式的
"
。Just do that:
And you will have your
"
in xml.您必须直接写入
"
,DomDocument 会负责对其进行转义。保存时,PostTitle 属性将被正确转义:
You have to write
"
directly, DomDocument takes care of escaping it.When saving, the PostTitle attribute will be properly escaped:
setAttribute() 默认情况下会转义,因此如果字符串已经转义,您可能需要使用 html_entity_decode():
setAttribute() does escaping by default so you might need to use html_entity_decode() if the string is already escaped: