我需要打开一个 http 外部 xml 文件,然后替换一些文本并将该文件保存在我的站点的托管中。
像这样的想法:
<?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);
?>
问题是我收到这条消息:
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...
两个文件都是可写的。
最佳答案
你不想写地址。只需将 +w
替换为 r
。
$xml_external_path = 'http://someplace.com/external_file.xml';
$xml_external = fopen($xml_external_path, "r");
....
看看those示例。
您还可以使用 file-get-contents功能。
file_get_contents("http://someplace.com/external_file.xml");
关于php - 如何用 fopen() 打开一个 http 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29098512/