dshyu6866 2014-03-08 05:00
浏览 42
已采纳

相对路径INSIDE file_get_contents结果

I am loading a url into my page on my local server with PHP file_get_contents. It works fine but relative paths on the site I am pulling obviously fail and default to my localhost.

Does anyone have any advice on how I could swap relative paths of a page I am pulling to absolute ones?

Ive tried something like this but it fails...

$homepage = file_get_contents($theURL);
$homepage2 = str_replace($homepage, "/images", $theURL + '/images');
echo $homepage2;

Thanks!

  • 写回答

1条回答 默认 最新

  • duancaishi1897 2014-03-08 05:10
    关注

    You're arguments for str_replace are in the wrong order.

    Instead of

    $homepage2 = str_replace($homepage, "/images", $theURL + '/images');
    

    You should be doing

    $homepage2 = str_replace("/images", $theURL + '/images', $homepage);
    

    http://php.net/str_replace

    str_replace(search, replace, subject)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器