[英]How can I send and receive data from an external webpage?
I am building a PHP script that needs to use content loaded from an external webpage, but I don't know how to send/receive data. 我正在构建一个PHP脚本,该脚本需要使用从外部网页加载的内容,但是我不知道如何发送/接收数据。
The external webpage is http://packer.50x.eu/ . 外部网页为http://packer.50x.eu/ 。
Basically, I want to send a script (which is manually done in the first form) and receive the output (from the second form). 基本上,我想发送一个脚本(以第一种形式手动完成)并接收输出(第二种形式)。
I want to learn how to do it because it can surely be an useful thing in the future, but I have no clue where to start. 我想学习如何做,因为这肯定会在将来有用,但是我不知道从哪里开始。
Can anyone help me? 谁能帮我? Thanks.
谢谢。
You can use curl
to receive data from external page. 您可以使用
curl
从外部页面接收数据。 Look this example: 看这个例子:
$url = "http://packer.50x.eu/";
$ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // you can use some options for this request
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // or not to use them
// you can set many others options. read about them in manual
$data = curl_exec($ch);
curl_close($ch);
var_dump($data); // < -- here is received page data
curl_setopt manual curl_setopt手册
Hope, this will help you. 希望这个能对您有所帮助。
You may want to look at file_get_contents($url) as it is very simple to use, simpler than CURL (more limited though), so your code could look like: 您可能要看一下file_get_contents($ url),因为它使用起来非常简单,比CURL更简单(尽管限制更多),因此您的代码可能如下所示:
$url = "http://packer.50x.eu/";
$url_content=file_get_contents($url);
echo $url_content;
Look at the documentation as you could use offset and other tricks. 请查看文档,因为您可以使用偏移量和其他技巧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.