html_entity_decode()和http_build_query()和file_get_contents()和file_put_contents()的用法

1:http_build_query() 作用是使用给出的关联(或下标)数组生成一个经过 URL-encode 的请求字符串。

列如:$data = array("name"=>"callback" , "value"=>"test");   

          $rescult = http_build_query($data);

输出得到 name=callback&value=test 解释:进行 url_encode 编码,并返回编码后的字符串,它的方便之处在于,可以直接将对象或数组编码,无论传入的数据是数组还是 object,解码后都将转换为数组。

作用是 http请求时把参数拼接在后面列如http://baidu.com/index?".http_build_query($data);

2:html_entity_decode()作用把字符转换为 HTML 实体。

例子:
$a = '<div> <p>11111&&222</p></div>';
$b = htmlentities($a);
$c = html_entity_decode($b);
echo $b."\n";
echo $c;
页面输出:
htmlentities输出内容:<div> <p>11111&&222</p></div>
html_entity_decode输出内容:11111&&222

3:file_get_contents()作用把整个文件读入一个字符串中,但经常用于php post或者get网页请求

列子:

$data = array( 'name'=>'zhezhao','age'=>'23');

$query = http_build_query($data);

$url = 'http://localhost/get.php';//这里一定要写完整的服务页面地址,否则php程序不会运行

$result = file_get_contents($url.'?'.$query);

4file_put_contents()作用把一个字符串写入文件中。一般系统做文件日志时会用

列子:

/**
* 写文件日志
* @param string $type Log目录下的子目录名
* @param string $content 日志内容
* @return bool
*/
define("PAYLOGS_PATH", "/www/wwwroot/agennhbbbcyuy.cbdjywg.com/data/");    (地址随便写的)
function diylogs($path,$content){
$today = date('Y-m-d').'.log';
if(!is_dir(PAYLOGS_PATH.$path)){
mkdir(PAYLOGS_PATH.$path,0777,true);
}
file_put_contents(PAYLOGS_PATH.$path.'/'.$today,date('Y-m-d H:i:s',time())."\r\n".print_r($content,true)."\r\n",FILE_APPEND);
}

 

posted @   无缺胜有缺  阅读(109)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示