我希望在电子邮件中包含整个xml字符串(包括标题,标签等)作为复制/粘贴的备份。 如果我使用以下:
<?php
$xml_content = file_get_contents('http://www.w3schools.com/xml/note.xml');
echo $xml_content;
?>
它显示:托芙贾尼提醒 这个周末不要忘记我!
而不是完整的字符串,这将是:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
如果希望页面内容类型完全输出文件,则必须将其设置为 xml 或纯文本。
header('Content-Type: text/xml');
或者如果这不起作用,那么
header('Content-Type: text/plain');
如果您希望在电子邮件中显示带有标记的XML,则必须将特殊的HTML标记转换为实体。
<?php
$xml_content = file_get_contents('http://www.w3schools.com/xml/note.xml');
echo htmlspecialchars($xml_content);
?>