php - Delphi IdHTTP.get 和 PHP file_get_contents 显示相同 URL 的不同文本

标签 php xml delphi http file-get-contents

我有这个link .

我已经无数次使用 IdHTTP.Get(link) (Delphi 2009) 成功下载了它的相应数据。

这是我得到的部分结果:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/&quot;DEIMRn47eCp7I2A9XRdXF0o.&quot;">
  <id>tag:youtube.com,2008:user:-lHJZR3Gqxm24_Vd_AJ5Yw</id>
  <published>2010-04-29T10:54:00.000Z</published>
  <updated>2014-10-31T17:29:47.000Z</updated>
  ...
</entry>

在 PHP 中我这样做:

$content = file_get_contents(link);
echo $content;

这是我在页面上看到的确切结果:

tag:youtube.com,2008:user:-lHJZR3Gqxm24_Vd_AJ5Yw2010-04-29T10:54:00.000Z2014-10-31T17:29:47.000ZBusinessy stuff: business dot pewdiepie at gmail dot comPewDiePiehttp_gdata.youtube.com/feeds/api/users/PewDiePie-lHJZR3Gqxm24_Vd_AJ5YwUC-lHJZR3Gqxm24_Vd_AJ5Yw117663191659499528404SE-lHJZR3Gqxm24_Vd_AJ5Ywpewdiepie

PHP 新手。请告诉我哪里错了。

最佳答案

您在 PHP 中得到相同的结果,但是您将它作为 HTML 输出到浏览器。浏览器忽略所有它不知道的标签并输出文本内容。在浏览器中打开源代码 View ,您将看到标签。

备选方案:

使用转义实体输出结果:

$content = file_get_contents(link);
echo htmlspecialchars($content);

将结果输出为纯文本:

$content = file_get_contents(link);
header('Content-Type: text/plain');
echo $content;

关于php - Delphi IdHTTP.get 和 PHP file_get_contents 显示相同 URL 的不同文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26681037/

相关文章:

php - 按外键计算行数

php - 如何避免JS代码变成input?

xml - 如何使用结构化 XML 数据编写事件日志条目?

delphi - Delphi Web脚本:执行脚本后访问变量

delphi - 应用程序定义的异常 - 不知道出了什么问题

delphi - 无法在 Windows 7 上运行 win32 exe

PHP:检索两个最新的 mySQL 表条目并将每个条目存储在不同的变量中

php - 从表php mysql中删除行

java - 如何从元素中获取值?

xml - 使用 Windows 批处理解析 XML 文件