PHP函数

1.json_decode()

json_decode(
string $json,
bool $assoc = false,
int $depth = 512,
int $options = 0
): mixed

assoc

当该参数为 true 时,将返回 array 而非 object 。

depth

指定递归深度。

options

由 JSON_BIGINT_AS_STRINGJSON_INVALID_UTF8_IGNOREJSON_INVALID_UTF8_SUBSTITUTEJSON_OBJECT_AS_ARRAYJSON_THROW_ON_ERROR 组成的掩码。

2.stream_context_create()

stream_context_create()创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。

$options可选项:

method:远程服务器支持的get、post或者其他http方法,默认值是get
header:请求期间发送的额外的header,在此选项值将覆盖其他值,详细可以查看http请求首部的键值对
user_agent:要发送的 header User-Agent: 的值
content:在header后边要发送的额外数据
proxy:URI指定代理服务器地址
timeout:读取超时时间,单位秒
ignore_errors:即使是故障状态码依然获取内容,默认false

$data = array(
'username' => 'user',
'password' => 'pass'
);
$data = http_build_query($data);
$options = array(
'http'=>array(
'method'=> 'POST',
'header'=> "Content-type:application/x-www-form-urlencoded\r\n".
"Accept-language:en\r\n".
"Cookie:t=lon\r\n".
"Content-length:".strlen($data)."\r\n",
'content'=> $data,
'timeout'=> 5
)
);

$url = 'http://www.test.com/ci/blog/createUser';
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);

 

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注