PHP XML DOM 不需要的转义字符,我不能写 &qnot;

发布于 2024-12-02 16:41:00 字数 699 浏览 1 评论 0原文

我有一个问题,

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无尽的现实 2024-12-09 16:41:00

只要这样做:

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

您将拥有 xml 格式的 "

Just do that:

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

And you will have your " in xml.

七颜 2024-12-09 16:41:00

您必须直接写入 ",DomDocument 会负责对其进行转义。

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

保存时,PostTitle 属性将被正确转义:

<... PostTitle="Sssa "" ...>

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 "" ...>
Saygoodbye 2024-12-09 16:41:00

setAttribute() 默认情况下会转义,因此如果字符串已经转义,您可能需要使用 html_entity_decode():

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

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文