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

如何用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.

图片转代码服务由CSDN问答提供 功能建议

我需要打开一个http外部xml文件,然后替换一些文本并将文件保存在我的网站托管中 。

Somethinkg是这样的:

 &lt;?php 
 
 $ xml_external_path ='http://someplace.com/  external_file.xml'; 
 $ xml_external = fopen($ xml_external_path,“w +”); 
 
 
 //这里是替换text 
 
 $ xml_local_path ='http://www.misite的代码。  com / local_file.xml'; 
 $ xml_local = fopen($ xml_sw_path,“w +”); 
 
 
fwrite($ xml_local,$ xml_external); 
 
 nclclose($ xml_external); 
 nclclose($ xml_local);  
?&gt; 
   
 
 

问题是我收到此消息:

警告:fopen( http://someplace.com/external_file.xml ):无法打开 流:HTTP包装器确实 不支持可写连接...

警告:fopen( http:// someplace.com/local_file.xml ):操作失败 en stream:HTTP包装器不支持...的可写连接

两个文件都是可写的。 \ n

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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"); 
    
    打赏 评论

相关推荐 更多相似问题