如何从外部网页发送和接收数据?

时间:2014-04-14 23:07:34

标签: php

我正在构建一个PHP脚本,需要使用从外部网页加载的内容,但我不知道如何发送/接收数据。

外部网页为http://packer.50x.eu/

基本上,我想发送一个脚本(以第一种形式手动完成)并接收输出(来自第二种形式)。

我想学习如何去做,因为它在将来肯定会有用,但我不知道从哪里开始。

任何人都可以帮助我吗?感谢。

2 个答案:

答案 0 :(得分:1)

您可以使用curl从外部页面接收数据。看这个例子:

$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

希望,这会对你有帮助。

答案 1 :(得分:1)

您可能希望查看file_get_contents($ url),因为它非常简单易用,比CURL更简单(虽然更有限),因此您的代码可能如下所示:

$url = "http://packer.50x.eu/";
$url_content=file_get_contents($url);
echo $url_content;

请查看文档,因为您可以使用偏移量和其他技巧。

相关问题