php 5.x 并忽略标签?

发布于 2024-10-07 04:17:35 字数 676 浏览 3 评论 0原文

这是我试图理解的代码片段;在我的网页设计课上,我了解到 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”
我需要它来打印 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 技术交流群。

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

发布评论

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

评论(2

能怎样 2024-10-14 04:17:35

从什么插值? Web 浏览器经常会尝试解析它......但 PHP 不会插入它,而是 Web 浏览器。确保使用正确的 mime 类型可能会有所帮助,但某些浏览器(例如 IE...)通常会尝试将所有内容模糊地呈现为 HTML 文本。

FWIW,邮政编码如下:(

$kml[] = '<href>http://vkhovanskaya.net/images/glow.png';

单击 ? 图标获取帮助...音译字符会使内容难以阅读。)

如果您确实想确保浏览器显示它,则需要将 < 转义为 & 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:

$kml[] = '<href>http://vkhovanskaya.net/images/glow.png';

(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 <

妥活 2024-10-14 04:17:35

您是否在浏览器中显示此内容?如果是这样,请查看页面源代码,您应该会看到您期望的 XML 节点。

如果您希望标记在 HTML 文档中呈现为可读,请使用 htmlspecialcharshtml实体

echo htmlspecialchars($kmlOutput);

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

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