<?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. txt写入时报错出现:正由另一进程使用,原来是多此一举的操作

    //if (!File.Exists(newfilepath + "\\" + name + num + ".txt")) //{ // File.Create ...

  2. Linux_(3)Shell编程(上)

    一.shell 简介Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言.Shell 是指一种应用程序,这个应用程序提供了一个 ...

  3. 转录组的组装Stingtie和Cufflinks

    转录组的组装Stingtie和Cufflinks Posted: 十月 18, 2017  Under: Transcriptomics  By Kai  no Comments 首先这两款软件都是用 ...

  4. qt 5.2.1类和模块的关系图

    QT│  ├─ActiveQt│  │  ActiveQt│  │  ActiveQtDepends│  │  ActiveQtVersion│  │  QAxAggregated│  │  QAxB ...

  5. ApplicationContext(九)初始化非延迟的 bean

    ApplicationContext(九)初始化非延迟的 bean 此至,ApplicationContext 已经完成了全部的准备工作,开始初始化剩余的 bean 了(第 11 步). public ...

  6. [JAVA]JAVA章1 数组数据去重

    一 利用HashSet进行去重 //定义一个数组:有几个重复项 int[] testarray = {1,2,33,4,2,3,44,5,222,3}; //利用HashSet对数组数据去重 Set& ...

  7. JDK8集合类源码解析 - HashSet

    HashSet 特点:不允许放入重复元素 查看源码,发现HashSet是基于HashMap来实现的,对HashMap做了一次“封装”. private transient HashMap<E,O ...

  8. java ajax请求后台并获取到返回值

    js: $.ajax({ url : '../Islogin.do', type : 'get', cache : false, dataType : 'json', success : functi ...

  9. 移动端Android软键盘遮住输入框解决!

    在使用vue的情况下,在输入框中添加 <textarea class="textarea" @click="isAndroid" :maxlength=& ...

  10. 42.OC中instancetype与id的区别

    区别: 在ARC(Auto Reference Count)环境下: instancetype用来在编译期确定实例的类型,而使用id的话,编译器不检查类型,运行时检查类型 在MRC(Manual Re ...