php常用函数之URL函数
2013-03-17 19:42
190 查看
base64_encode($str) 对字符进行base64加密,此加密主要是为了便于传输
base64_decode($str) 对进行base64加密的字符串进行解密
urlencode($str)编码url字符串
urldecode($str)解码已经编码的url字符串
rawurlencode($str)按照RFC 1738对url进行编码
rawurldecode($str)对编码的url进行解码
get_headers($url);获取一个http请求的返回信息
get_meta_tags($file_url); 获取页面中的meta信息
http_build_query($arr) 将一个数组生成一个url请求串
parse_url($url);解析url并返回组成部分的数组,若某部分没有,则不创建改元素
举例
base64_decode($str) 对进行base64加密的字符串进行解密
urlencode($str)编码url字符串
urldecode($str)解码已经编码的url字符串
rawurlencode($str)按照RFC 1738对url进行编码
rawurldecode($str)对编码的url进行解码
get_headers($url);获取一个http请求的返回信息
get_meta_tags($file_url); 获取页面中的meta信息
http_build_query($arr) 将一个数组生成一个url请求串
parse_url($url);解析url并返回组成部分的数组,若某部分没有,则不创建改元素
举例
<?php //base64_encode($str) 对字符进行base64加密,此加密主要是为了便于传输 //base64_decode($str) 对进行base64加密的字符串进行解密 $str = "我爱北京天安门1233fasfhsafsaffsahfsajf我爱死你鞥路eahdhafffjf2345555"; $str1 = base64_encode($str); echo $str1; echo "<br/>"; echo base64_decode($str1); //urlencode($str)编码url字符串 //urldecode($str)解码已经编码的url字符串 //rawurlencode($str)按照RFC 1738对url进行编码 //rawurldecode($str)对编码的url进行解码 //urlencode()和rawurlencode()区别就是当字符串中有空格时,urlencode()转化成+,而rawurlencode()转化成%20; $str = "safsj!@#$%Z^&*Z()_+我爱北京天安门 "; echo rawurlencode($str); echo "<br/>"; echo urlencode($str); //get_headers($url);获取一个http请求的返回信息 $url = 'http://www.sina.com.cn'; echo "<pre>"; print_r(get_headers($url)); echo "<br/>"; print_r(get_headers($url,1)); /* Array ( [0] => HTTP/1.0 200 OK [1] => Last-Modified: Sun, 17 Mar 2013 11:32:21 GMT [2] => Accept-Ranges: bytes [3] => X-Powered-By: mod_xlayout/rc2 [4] => Content-Type: text/html [5] => Date: Sun, 17 Mar 2013 11:36:04 GMT [6] => Server: Apache [7] => Expires: Sun, 17 Mar 2013 11:37:04 GMT [8] => Cache-Control: max-age=60 [9] => Vary: Accept-Encoding [10] => Age: 52 [11] => Content-Length: 695395 [12] => X-Cache: HIT from xd33-83.sina.com.cn [13] => Connection: close ) Array ( [0] => HTTP/1.0 200 OK [Last-Modified] => Sun, 17 Mar 2013 11:32:21 GMT [Accept-Ranges] => bytes [X-Powered-By] => mod_xlayout/rc2 [Content-Type] => text/html [Date] => Sun, 17 Mar 2013 11:36:23 GMT [Server] => Apache [Expires] => Sun, 17 Mar 2013 11:37:23 GMT [Cache-Control] => max-age=60 [Vary] => Accept-Encoding [Age] => 33 [Content-Length] => 695395 [X-Cache] => HIT from xd33-81.sina.com.cn [Connection] => close ) */ //index1.html中必须包含如下格式的内容,才会返回有值的数组 // <meta name="type" http-equiv="content-type" content="text/html; charset=utf-8"> // <meta name="desc" http-equiv="content-type" content="我做个测试"> $tags = get_meta_tags('./index1.html'); echo "<pre>"; print_r($tags); echo "<br/>"; /* Array ( [type] => text/html; charset=utf-8 [desc] => 我做个测试 ) */ //parse_url($url);解析url并返回组成部分的数组,若某部分没有,则不创建改元素 $arr = parse_url('http://finance.sina.com.cn/consume/qyzh/20130316/123014854680.shtml'); echo "<pre>"; print_r($arr); //http_build_query($arr) 将一个数组生成一个url请求串 $para_arr = array('id'=>1,'sex'=>0,'name'=>'lisi'); echo "<pre>"; print_r (http_build_query($para_arr)); //id=1&sex=0&name=lisi
相关文章推荐
- php常用的url处理函数总结
- php常用的url处理函数总结
- php中session常用函数
- PHP 中英文混合排版中处理字符串常用的函数
- php常用函数
- PHP常用函数总结(180多个)[持续更新中...]
- php--字符串常用函数
- JSP-JSTL-import、redirect、url处理、常用函数
- php自主常用函数
- PHP数组常用函数
- php 常用函数收集
- PHP函数汇集 常用的函数 PHP易出错的函数
- php 数组,常用函数
- PHP 常用函数
- php中常用的字符串格式化函数
- 自定义PHP页面跳转函数redirect($url, $time = 0, $msg = '')
- PHP编写扩展时的几个常用函数
- PHP 正则表达式常用函数
- PHP 常用函数整理
- php常用函数