我正在开发一个项目,我想包含一个将在Pastebin上托管的HTML脚本。包含远程HTML文件
喜欢的东西:
include 'http://pastebin.com/raw/testiungshdhd';
我试图
fgets(fopen('http://pastebin.com/raw/asdasddaqwe', 'r'));
但负。
我正在开发一个项目,我想包含一个将在Pastebin上托管的HTML脚本。包含远程HTML文件
喜欢的东西:
include 'http://pastebin.com/raw/testiungshdhd';
我试图
fgets(fopen('http://pastebin.com/raw/asdasddaqwe', 'r'));
但负。
尝试卷曲:
http://php.net/manual/en/book.curl.php
基本例如:
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
所以没有其他方式像'include''一样简单';'? –
其中还包括。你可以编写一个函数,例如curl_include()和字符串参数,它的工作原理与include相同。 – RaV
你可以用file_get_contents
做到:
$data = file_get_contents('http://pastebin.com/raw/JyEcHhy2');
首先,你需要启用设置php.ini文件: -
allow_url_include=On
然后有几个可能的方式来实现这一目标:
方法1:
<?php
include("http://pastebin.com/raw/asdasddaqwe");
?>
方法2:
<?php
echo file_get_contents("http://pastebin.com/raw/asdasddaqwe");
?>
只有在您信任远程源文件时才这样做,您试图将其包括在内。
http://stackoverflow.com/questions/1158348/including-a-remote-file-in-php – Suyog