php 5.x 并忽略标签?
这是我试图理解的代码片段;在我的网页设计课上,我了解到 php 单引号 ' ' 将所有内容按字面意思解释为字符串。但是,在此代码中:
$kml = array();
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
$kml[] = ' <Document>';
$kml[] = ' <Style id="hitStyle">';
$kml[] = ' <IconStyle id="hitIcon">';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://vkhovanskaya.net/images/glow.png</href>';
$kml[] = ' </Icon>';
$kmlOutput = $kml[5];
print($kmlOutput);
打印:“http://vkhovanskaya.net/images/glow.png”
我需要它来打印
因为它是 kml 文件是什么(我需要标记)
我应该做什么来转义 << >来自解释尝试?
Here is a snippet of the code I'm trying to understand; in my web design class, I learned that php single quotes ' ' interpret everything literally, as a string. However, in this code:
$kml = array();
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
$kml[] = ' <Document>';
$kml[] = ' <Style id="hitStyle">';
$kml[] = ' <IconStyle id="hitIcon">';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://vkhovanskaya.net/images/glow.png</href>';
$kml[] = ' </Icon>';
$kmlOutput = $kml[5];
print($kmlOutput);
prints: "http://vkhovanskaya.net/images/glow.png"
and I need it to print <href>http://vkhovanskaya.net/images/glow.png</href>
because it's part of
what will be a kml file (I need the markup tags)
What should I be doing to escape the < > from interpretation attempts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从什么插值? Web 浏览器经常会尝试解析它......但 PHP 不会插入它,而是 Web 浏览器。确保使用正确的 mime 类型可能会有所帮助,但某些浏览器(例如 IE...)通常会尝试将所有内容模糊地呈现为 HTML 文本。
FWIW,邮政编码如下:(
单击 ? 图标获取帮助...音译字符会使内容难以阅读。)
如果您确实想确保浏览器显示它,则需要将 < 转义为 & LT;
Interpolation from what? A web browser will often try to parse it... but PHP isn't interpolating it, the web browser is. Making sure you are using the right mime-type may help, but some browsers (like IE...) will often try to render everything vaguely like text as HTML.
FWIW, post code like:
(Click the ? icon for help... transliterating characters makes things hard to read.)
If you really want to ensure a browser displays it, you'll need to escape the <'s as <
您是否在浏览器中显示此内容?如果是这样,请查看页面源代码,您应该会看到您期望的 XML 节点。
如果您希望标记在 HTML 文档中呈现为可读,请使用 htmlspecialchars 或html实体
Are you displaying this in a browser? If so, view the page source and you should see your XML node as you expect.
If you want the markup to render as readable in an HTML document, use htmlspecialchars or htmlentities