PHP XML DOM不需要转义字符,我不能写&qnot;
我在与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
"
*/
为什么是一个问题???我找不到逻辑解释...
只是做到这一点:
$Title = str_replace("-==single-quote==--", ' " ',$Title);
$Title = str_replace('-==double-quote==--', ' " ',$Title);
你将在xml中使用你的"
。
这实际上有效,但是,哦,男孩,他们有默认编码??大声笑! – Master345
@Row Minds你读过所有的答案吗? – arnaud576875
你必须直接写"
,DomDocument负责转义它。
$Title = "Sssa &";
...
...->setAttribute("PostTitle", $Title);
保存时,该PostTitle属性将被正确转义:
<... PostTitle="Sssa "" ...>
的setAttribute()并在默认情况下逃脱,所以你可能需要使用html_entity_decode()如果字符串已经转义:
$href2->setAttribute("PostTitle", html_entity_decode($Title));
没有解决方案正常工作。面对实体相关问题。 –
*(相关)* http://stackoverflow.com/questions/6716486/convert-spaces-between-pre-tags-via-dom-parser/6716538#6716538 – Gordon