2014-11-09 161 views
-1

如何从包含函数file_get_contents()的file_get_contents()文件中获取内容以从另一个文件获取内容?PHP file_get_contents()来自另一个文件file_get_contents()

为axample:

a.php只会 - >的file_get_contents(b.php)

b.php - >的file_get_contents(www.google.com)

我想有从HTML输出www.google.com在a.php只会

编辑:a.php只会是一个不同的服务器b.php

+3

不会'包含“b.php”'执行b.php比'file_get_contents(b.php)'更好吗? – 2014-11-09 00:25:05

+0

在另一台服务器上:S – 2014-11-09 00:27:29

+1

使用'file_get_contents'从文件中读取只会得到该文件的内容,它不会被解析为PHP。如果B可通过HTTP访问,则可以使用带有'file_get_contents'的HTTP URL,然后_该文件将被解析。但是,这看起来有些复杂 - 您不能直接在A中请求目标URL的原因是什么? – CBroe 2014-11-09 00:27:52

回答

-2

用同样的方法你从另一个文件的内容,不`吨有file_ge上t_contents,您可以根据需要尽可能多地使用file_get_contents()多次。

对于前:

1.PHP

<?php 

echo file_get_contents("2.php"); 

?> 

2.PHP

<?php 

echo file_get_contents("3.php"); 

?> 

3.php

<?php 

echo "OK"; 

?> 

输出将是 - OK

+0

上,但无法工作。我在这两个文件中只有该功能,但导致a.php为空。我得到了json结果,但是html标记的字段为空 – 2014-11-09 00:25:45

+0

输出是否“OK”?我想不是! – 2014-11-09 00:25:55

+1

如果它在同一台服务器上,那不起作用。 '2.php'会在'3.php'中回显PHP代码。如果2和2在不同的服务器上,它将工作。 – Rudie 2014-11-09 00:26:42

0

a.php只会(在第一台服务器)

<?php 

echo file_get_contents("http://mysecondserver.com/b.php"); 

?> 

b.php(在第二个服务器)

<?php 

echo file_get_contents("http://www.google.com"); 

?> 

当您打开a.php只会,它是要采取B的html内容.php和b.php正在采用google.com的html内容,所以我猜你已经完成了。

+0

b.php在不同的服务器上 – 2014-11-09 00:35:03

+0

Manuel Z,好的,那么在问题中写下它怎么样?切肉刀对不对? – 2014-11-09 00:36:38

+0

@ManuelZ试试这个,我更新了。 – 2014-11-09 00:52:07