<?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. 修改JEECG项目浏览器标题

    方法1: 在线修改,在平台自带的功能“系统管理”——“国际化语言” 中搜索 jeect.platform,修改显示文字重启生效. 方法2: 修改数据表t_s_muti_lang中id为"40 ...

  2. js倒计时跳转页面实现

  3. iOS.ChangeIniOS7

    1. Multitasking in iOS 7 http://www.objc.io/issue-5/multitasking.html http://www.slideshare.net/mrem ...

  4. python中的迭代器 生成器 装饰器

    什么迭代器呢?它是一个带状态的对象,他能在你调用next()方法的时候返回容器中的下一个值,任何实现了__iter__和__next__()(python2中实现next())方法的对象都是迭代器,_ ...

  5. HTML的报告

    import HTMLTestRunner class HTMLReporter(object): def reporter(self,filename,reportername,reporterdi ...

  6. NC 6系预警类型注册

    在实际开发预警任务中,因为模块是新创建的,所以开发预警,就要在相应的节点模块注册.但这样代码就得放在相应的模块中,注册个预警类型,就可以把代码直接放在自己新建的模块. .先执行新建模块语句 inser ...

  7. 条件随机场_CRF

    无向图 举例:“Bob drank coffee at Starbucks” 标记方式1:(名词,动词,名词,介词,名词) 称为l 标记方式2:(名词,动词,动词,介词,名词) 挑选出一个最靠谱的: ...

  8. Tomcat优化详细1

    在Tomcat和应用程序进行了压力测试后,如果您对应用程序的性能结果不太满意,就可以采取一些性能调整措施了,当然了前提是应用程序没有问题,我们这里只讲Tomcat的调整.由于Tomcat的运行依赖于J ...

  9. java 中java.util.Arrays类---常用函数记录

    java.util.Arrays主要是用来对数组进行操作的类,主要包括以下方法: 1.数组转化列表,得到固定大小的列表,Arrays.asList(...): public static <T& ...

  10. 子数整数(P1151&NOIP水题测试(2017082301))

    题目链接:子数整数 水题,不解释,自己看代码: #include<bits/stdc++.h> using namespace std; int main(){ int k; scanf( ...