开发者

PHP XML DOM unwanted escaping characters, i cannot write &qnot;

i'm having a problem with

$xml2 = new DOMDocument;
$xml2->load($FilenamePost."/".$FilenameOfTh开发者_StackOverflow社区ePost.'.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 ...


Just do that:

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

And you will have your " in xml.


You have to write " directly, DomDocument takes care of escaping it.

$Title = "Sssa &";
...
...->setAttribute("PostTitle", $Title);

When saving, the PostTitle attribute will be properly escaped:

<... PostTitle="Sssa &quot;" ...>


setAttribute() does escaping by default so you might need to use html_entity_decode() if the string is already escaped:

$href2->setAttribute("PostTitle", html_entity_decode($Title));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜