2016-05-13 117 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"); 
?> 

只有在您信任遠程源文件時才這樣做,您試圖將其包括在內。