//简单实现json到php数组转换功能 private function simple_json_parser($json){ $json = str_replace("{","",str_replace("}","", $json)); $jsonValue = explode(",", $json); $arr = array(); foreach($jsonValue as $v){ $jValue = explode(":", $v); $arr[str_replace('"',"", $jValue[0])] = (str_replace('"', "", $jValue[1])); } return $arr; }
赋值并继续执行
if($tmpVal == $pre){//则使用默认的值 continue; }else if($tmpVal){ $arr[$tmpKey] = $tmpVal; }
生成唯一随机串 $state = md5(uniqid(rand(), TRUE));
把整个文件读入数组:
file() 函数把整个文件读入一个数组中。
与 file_get_contents() 类似,不同的是 file() 将文件作为一个数组返回。数组中的每个单元都是文件中相应的一行,包括换行符在内。
如果失败,则返回 false。
例子:
<?php print_r(file("test.txt")); ?>
输出:
Array ( [0] => Hello World. Testing testing! [1] => Another day, another line. [2] => If the array picks up this line, [3] => then is it a pickup line? )
php中的ini_set函数是php自带的用来修改设置php.ini配置文件的函数,用这个函数很方便,不用去手动修改php.ini文件,有时候我们也没有权限去修改php.ini文件,这时就用这个函数。
语法:ini_set("选项","值");该函数用时最好放到php的脚本最头部
比如:ini_set("max_execution_time", "180");//设置php的脚本超时时间为180秒
string ini_get (string varname );返回选项的值,如果选项的值为布尔型则返回为0或1
比如:echo ini_get('max_execution_time');//输出 30
如果想获取整个php.ini里的变量值,我们可以用ini_get的加强函数 ini_get_all()它以数组的形式返回整个php的环境变量。
get_headers — 取得服务器响应一个 HTTP 请求所发送的所有标头
array get_headers ( string$url [, int$format = 0 ] )
get_headers() 返回一个数组,包含有服务器响应一个 HTTP 请求所发送的标头。
返回值: 返回包含有服务器响应一个 HTTP 请求所发送标头的索引或关联数组,如果失败则返回 FALSE。
<?php $url = 'http://www.example.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); ?>
Array (
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 29 May 2004 12:28:13 GMT
[2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
[3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
[4] => ETag: "3f80f-1b6-3e1cb03b"
[5] => Accept-Ranges: bytes
[6] => Content-Length: 438
[7] => Connection: close
[8] => Content-Type: text/html )
Array (
[0] => HTTP/1.1 200 OK
[Date] => Sat, 29 May 2004 12:28:14 GMT
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
[ETag] => "3f80f-1b6-3e1cb03b"
[Accept-Ranges] => bytes
[Content-Length] => 438
[Connection] => close
[Content-Type] => text/html )
代码中出现乱码添加:
echo "<meta charset=\"UTF-8\">";
防盗链
如果本网站的图片不想让其它网站调用,可以在 .htaccess或者apche的配置文件httpd.conf文件中添加以下内容
RewriteEngine on #开启Rewrite模块 RewriteCond %{HTTP_REFERER} !^$ #如果不是直接输入图片地址 RewriteCond %{HTTP_REFERER} !img.clin003.com$ [NC] #且如果不是img.clin003.com所有子域名调用的 RewriteCond %{HTTP_REFERER} !img.clin003.com/(.*)$ [NC] RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC] RewriteCond %{HTTP_REFERER} !google.com [NC] RewriteCond %{HTTP_REFERER} !google.cn [NC] RewriteCond %{HTTP_REFERER} !baidu.com [NC] RewriteCond %{HTTP_REFERER} !feedsky.com [NC] RewriteRule (.*)\.(jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf)$ http://clin003.com/err.jpg [R=301,L,NC] #截获所有.jpg或.jpeg……请求,跳转到http://clin003.com/err.jpg提示错误的图片,注:该图片不能在原域名下,也不能在该.htaccess文件有效控制的文件夹中