|
<?php
define ( 'MAGIC_QUOTES_GPC', function_exists ( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc () );
define ( 'ICONV_ENABLE', function_exists ( 'iconv' ) );
define ( 'MB_ENABLE', function_exists ( 'mb_convert_encoding' ) );
define ( 'EXT_OBGZIP', function_exists ( 'ob_gzhandler' ) );
/**
* 发送HTTP状态信息
*
* @param int $code 状态代码
*/
function send_http_status($code) {
static $_status = array(
// Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',
// Success 2xx
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
// Redirection 3xx
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Moved Temporarily ', // 1.1
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
// 306 is deprecated but reserved
307 => 'Temporary Redirect',
// Client Error 4xx
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
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',
// Server Error 5xx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
509 => 'Bandwidth Limit Exceeded'
);
if(array_key_exists($code,$_status)) header('HTTP/1.1 '.$code.' '.$_status[$code]);
}
/**
* 区分大小写的文件存在判断
* @param $string 需要处理的文件路径
* @return boolean 存在返回true,否则返回 false
*/
function file_exists_case($filename) {
if(is_file($filename)){
if(IS_WIN && defined('APP_FILE_CASE')){
if(basename(realpath($filename)) != basename($filename)) return false;
}
return true;
}
return false;
}
//切分数组参数 $skip 为跳过的item
function implodearray($array, $skip = array()) {
$return = '';
if (is_array ( $array ) && ! empty ( $array )) {
foreach ( $array as $key => $value ) {
if (empty ( $skip ) || ! in_array ( $key, $skip )) {
if (is_array ( $value )) {
$return .= "$key={" . implodearray ( $value, $skip ) . "}; ";
} else {
$return .= "$key=$value; ";
}
}
}
}
return $return;
}
//用法
$extralog = implodearray ( array ('GET' => $_GET, 'POST' => $_POST ), array ('formhash', 'submit', 'addsubmit', 'admin_password', 'sid', 'action' ) );
function ParCv($n) {
return chr ( $n );
}
function strexists($string, $find) {
return ! (strpos ( $string, $find ) === FALSE);
}
function jstrim($str, $len) {
$str = preg_replace ( "/{quote}(.*){\/quote}/is", '', $str );
$str = str_replace ( '<br/>', ' ', $str );
$str = cn_substr ( $str, $len );
$str = ereg_replace ( "['\"\r\n]", "", $str );
return $str;
}
function jstrimjajx($str, $len) {
$str = preg_replace ( "/{quote}(.*){\/quote}/is", '', $str );
$str = str_replace ( '<br/>', ' ', $str );
$str = cn_substr ( $str, $len );
$str = ereg_replace ( "['\"\r\n]", "", $str );
$str = str_replace ( '<', '<', $str );
$str = str_replace ( '>', '>', $str );
return $str;
}
/*
* 功能:格式化数字,以标准MONEY格式输出
*/
function formatMoney($money)
{
if ($money * 100 < 1) {
return 0;
}
return substr(sprintf("%.3f", $money), 0, -1);
}
/*
* 功能:格式化文本,将\n转成<br>等
* 参数:$string 来源字符串
* 返回:处理后的字符串
*/
function formatString($string = "") {
$string = preg_replace ( array ("/ /", "/ /" ), array (" ", " " ), $string );
return nl2br ( $string );
}
/*
* 功能:格式化文本输出
* 参数 $text 为需格式化的文本内容
*/
function formatContent($text) {
$trans = get_html_translation_table ( HTML_SPECIALCHARS );
$trans = array_flip ( $trans );
$text = strtr ( $text, $trans );
//$text = str_replace("\n", "<br>", $text);
//$text = str_replace(" ", " ", $text);
return $text;
}
/**
* 代码调试
*/
function dd() {
echo '<pre>';
array_map(function ($x) {
print_r($x);
}, func_get_args());
die;
}
?> |
|