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

如何用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 12: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"); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access中怎么分割分别获取一下图中的值
  • ¥15 keras_tcn已经安装成功,还是显示ModuleNotFoundError: No module named 'keras_tcn'
  • ¥15 类图中关联与聚合的区别
  • ¥15 ENVI高分五号去除云层的方法
  • ¥15 16进制数据如何得到奇偶校验位
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题