<?php
/**
*
*/
class Common
{
if(!function_exists('is_php'))
{
function is_php($version = '5.0.0')
{
static $_is_php;
$version = (string)$version; if(!isset($_is_php[$version]))
{
$_is_php[$version] = (version_compare(PHP_VERSION, $version));
} return $_is_php[$version];
}
} function is_really_writable($file)
{
if(DIRECTORY_SEPARATOR == '/' AND @ini_get('safe_mode') == FALSE)
{
return is_writable($file);
} if(is_dir($file))
{
$file = rtrim($file, '/').'/'.md5(mt_rand(1, 100).mt_rand(1, 100));
//mt_rand更好的生成随机数
if(($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
{
return FALSE;
}
fclose($fp);
@chmod($file, DIR_WRITE_MODE);
@unlink($file);
return TRUE;
}
elseif(!is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
{
return FALSE;
}
fclose($fp);
return TRUE;
} function set_status_header($code = 200, $text = '')
{
$static = array(
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Infomation',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content', 300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
305 => 'Use Proxy',
307 => 'Temporary Redirect', 400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Fund',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed', 500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);
if($code == '' OR !is_numeric($code))
{ } if(isset($static[$code]) AND $text == '')
{
$text = $static[$code];
} $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL']:FALSE; if(substr(php_sapi_name(), 0, 3) == 'cgi')
{
header("Status: {$code} {$text}". TRUE);
}
} function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displables = array(); if($url_encoded)
{
$non_displables[] = '/%0[0-8bcef]/';
$non_displables[] = '/%1[0-9a-f]/';
} $non_displables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; do
{
$str = preg_replace($non_displables, '', $str, -1, $count);
}
while($count); return $str;
} function html_escape($var)
{
if(is_array($var))
{
return array_map('html_escape', $var);
}
else
{
return htmlspecialchars($var, ENT_QUOTES, $carsets);
}
} function change_list_key_sort($key, array $arr, $order = 'asc')
{
$result = array();
foreach( $arr as $item)
{
if(false == is_array($item) || false == array_key_exists($key, $item))
{
break;
$result = array();
}
$result[$item[$key]] = $item;
} $order == 'asc' ? ksort($result) : krsort($result);
return $result;
}
}

common.php的更多相关文章

  1. Socket聊天程序——Common

    写在前面: 上一篇记录了Socket聊天程序的客户端设计,为了记录的完整性,这里还是将Socket聊天的最后一个模块--Common模块记录一下.Common的设计如下: 功能说明: Common模块 ...

  2. angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)

    common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...

  3. Common Bugs in C Programming

    There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...

  4. ANSI Common Lisp Practice - My Answers - Chatper - 3

    Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...

  5. [LeetCode] Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  6. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  8. 48. 二叉树两结点的最低共同父结点(3种变种情况)[Get lowest common ancestor of binary tree]

    [题目] 输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点. 二叉树的结点定义如下:  C++ Code  123456   struct BinaryTreeNode {     int ...

  9. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  10. 【leetcode】Longest Common Prefix

    题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...

随机推荐

  1. Contest with Drinks Easy

    /* Problem Statement Joisino is about to compete in the final round of a certain programming competi ...

  2. HDOJ4261 Estimation

    一道需要用堆初始化的\(DP\) 原题链接 显然对于每一个部分,当\(b[i]\)为\(a\)对于部分的中位数时,差错最小.设\(S(x,y)\)表示\(x\sim y\)这一部分的差错. \(DP\ ...

  3. css 需要阴影的效果

    box-shadow: 0 0 10px 10px #b9bcbf; CSS3 box-shadow 属性 CSS 参考手册 实例 向 div 元素添加 box-shadow: div { box-s ...

  4. 查看CPU核数和内存

    查看CPU核数 top 然后按数字键1 通过虚拟文件系统proc,直接获取CPU总数量 cat /proc/cpuinfo | grep processor 查看内存 free命令主要用于显示内存数量 ...

  5. Vuebnb 一个用 vue.js + Laravel 构建的全栈应用

    今年我一直在写一本新书叫全栈Vue网站开发:Vue.js,Vuex和Laravel.它会在Packt出版社在2018年初出版. 这本书是围绕着一个案例研究项目,Vuebnb,简单克隆Airbnb.在这 ...

  6. c++11 初始化列表 bind function 示例

    // 111111111111.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #incl ...

  7. sqlserver 误删数据库恢复

    本文为转载 原文:https://blog.csdn.net/xwnxwn/article/details/53537841 由于长时间从事企业应用系统开发,前往用户现场升级.调试系统是比较常做的事情 ...

  8. js 文件下载 进度条

    js: /** * 下载文件 - 带进度监控 * @param url: 文件请求路径 * @param params: 请求参数 * @param name: 保存的文件名 * @param pro ...

  9. JDBC连接MySql,配置url报错

    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one ...

  10. svn 修改原来包名的方法和会报的错误

    SVN E200009 which is not part of the commit; both sides of the move must be committed together 在svn上 ...