【问题标题】:How to make 'file_get_contents' accessing a remote URL use the original hyperlinks?如何使访问远程 URL 的“file_get_contents”使用原始超链接?
【发布时间】:2013-10-30 10:09:58
【问题描述】:

我正在尝试使用“file_get_contents”将 .php 文件插入网页正文。当显示远程内容时,所有链接都不起作用,因为它在本地请求它们。作为一个新手,有没有办法设置“file_get_contents”输出以显示原始超链接?上下文变量会是解决方案吗?

这是我在网页中的 php:

<?php echo file_get_contents("http://acs.klikapps.co.uk/stock.php"); ?>

谢谢!

【问题讨论】:

  • file_get_contents() 不会为您执行此操作....您需要在变量中获取 file_get_contents() 的结果,然后对其进行解析以识别和修改链接使用domDocument 或类似

标签: php url file-get-contents


【解决方案1】:

应该这样做:

<?php echo str_replace("stock.php?", "http://acs.klikapps.co.uk/stock.php?", file_get_contents("http://acs.klikapps.co.uk/stock.php")); ?>

【讨论】:

    【解决方案2】:

    您需要修改返回的 HTML 以将相对链接替换为绝对路径,或者更简单的解决方案是将&lt;base href='http://the-site.com/folder/" /&gt; 标记添加到返回页面的&lt;head&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2012-05-18
      • 2022-11-01
      相关资源
      最近更新 更多