dop82210 2015-03-17 03:58
浏览 371
已采纳

如何用fopen()打开http文件?

I need to open a http external xml file, then replace some text and save the file in the hosting of my site.

Somethinkg like this:

<?php

$xml_external_path = 'http://someplace.com/external_file.xml';
$xml_external = fopen($xml_external_path, "w+");


//here the code to replace text

$xml_local_path = 'http://www.misite.com/local_file.xml';
$xml_local = fopen($xml_sw_path, "w+");

fwrite($xml_local, $xml_external);

fclose($xml_external);
fclose($xml_local);
?>

Problem is that I get this message:

Warning: fopen(http://someplace.com/external_file.xml): failed to open stream: HTTP wrapper does not support writeable connections at...

Warning: fopen(http://someplace.com/local_file.xml): failed to open stream: HTTP wrapper does not support writeable connections at...

Both files are writeable.

  • 写回答

1条回答 默认 最新

  • dongshuo1856 2015-03-17 04:03
    关注

    You dont want to write to the address. Just replace the +w with r.

    $xml_external_path = 'http://someplace.com/external_file.xml';
    $xml_external = fopen($xml_external_path, "r");
    ....
    

    Have a look at those examples.

    You could also use the file-get-contents function.

    file_get_contents("http://someplace.com/external_file.xml"); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部