今天主要看了下PHP支持的协议和封装的协议,主要了解了一下PHP中的配置协议方面的东西,弄明白了以前比较模糊的stream_context_create()等上下文方法,还没有完全看完,先将自己的片段代码贴在这里,mark一下。
<?php
/**
* Created by PhpStorm.
* User: f3ngt1ng
* Date: 2017/2/14
* Time: 9:14
* Today is lovers' day~~
*/
//上下文(context)选项和参数(支持的协议和封装协议)
//allow_url_fopen = 1
/*
$url = 'http://www.baidu.com';
$fp = fopen($url, 'r');
$meta_data = stream_get_meta_data($fp);
$stream_contents = stream_get_contents($fp);
var_dump($meta_data);
*/
//echo ini_get('allow_url_fopen');
//print_r($stream_contents); //php://
/*$fp = fopen('php://stdin', 'r');
while($line = fgets($fp)){
fwrite(STDOUT, $line);
//echo $line.'xx'.'\r\n';
}
fclose($fp);
*/
//echo sys_get_temp_dir();
//哪些受allow_url_fopen影响
/*
$url = 'http://www.google.com';
readfile("php://filter/read=string.rot13/resource=$url");
file_put_contents("php://filter/write=string.toupper/resource=xxx", 'hello,world~');
*/
//ini_set("allow_url_fopen", 0);
//echo ini_get('allow_url_fopen');
//readfile('http://www.baidu.com');
/*
$fp = fopen("php://filter/write=string.toupper|convert.base64-encode/resource=filter.txt" ,'w');
fputs($fp, 'hello,world');
fclose($fp);
*/
/*
$file = fopen('filter.txt', 'r');
stream_filter_append($file, 'convert.base64-decode', STREAM_FILTER_READ); while($line = fgets($file)){
echo $line;
} fclose($file);
*/
// readfile vs fopen/fgets/fgetc
//readfile("php://filter/read=convert.base64-decode/resource=filter.txt");
//$filters = stream_get_filters();
//print_r($filters);
//$wrappers = stream_get_wrappers();
//print_r($wrappers);
/*
$fp = fopen('data://text/plain;base64,SEVMTE8sV09STEQ=', 'r');
$media_type = stream_get_meta_data($fp);
echo $media_type['mediatype'];
print_r($media_type);*/ //echo ini_get('allow_url_include');
ini_set('allow_url_include', 'On');
//需要allow_url_fopen打开
echo ini_get('allow_url_include');