file_get_contents函数简单实用以及在PHP文件中调用其他网页,API

1.file_get_contents(path,include_path,context,start,max_length);
path 必需。规定要读取的文件。
include_path 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1",不需要设置为 false。
context 可选。规定文件句柄的环境。是一套可以修改流的行为的选项。若使用 null,则忽略。
句柄:文件的唯一标识符,和人的名字一样,只是不重名。句柄环境我也说不太清楚,就是根据要读取的文件类型,规定相应的协议,如果有哪位可以回答,劳驾写到评论中,谢谢!!
start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。
max_length 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。

2.context 参数配合 stream_context_create 函数使用
resource stream_context_create ([ array $options [, array $params ]] )
创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。
例:
$SendData['mobile'] = $req->body->mobile;
$SendData['sms_type'] = 0;
$SendData = json_encode($SendData);

$opts['http']['method'] = 'POST';
$opts['http']['content'] = $SendData;
$opts['http']['header'] = "Content-Type: application/json" . " " . "Content-length:" . strlen($SendData) . " ";
$Context = stream_context_create($opts);
$ApiUrl = 'www.xxxx.com'
$ReStr = file_get_contents($ApiUrl, false, $Context);

原文地址:https://www.cnblogs.com/wsh-ning/p/7595686.html