2016-05-13 109 views
3

我正在开发一个项目,我想包含一个将在Pastebin上托管的HTML脚本。包含远程HTML文件

喜欢的东西:

include 'http://pastebin.com/raw/testiungshdhd';  

我试图

fgets(fopen('http://pastebin.com/raw/asdasddaqwe', 'r')); 

但负。

+3

http://stackoverflow.com/questions/1158348/including-a-remote-file-in-php – Suyog

回答

1

尝试卷曲:

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); 

编号:http://php.net/manual/en/curl.examples-basic.php

+0

所以没有其他方式像'include''一样简单';'? –

+0

其中还包括。你可以编写一个函数,例如curl_include()和字符串参数,它的工作原理与include相同。 – RaV

0

你可以用file_get_contents做到:

$data = file_get_contents('http://pastebin.com/raw/JyEcHhy2'); 
3

首先,你需要启用设置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"); 
?> 

只有在您信任远程源文件时才这样做,您试图将其包括在内。