mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
34 lines
979 B
PHP
34 lines
979 B
PHP
<?php
|
|
|
|
/**
|
|
* 打印输出数据到文件
|
|
* @param mixed $data
|
|
* @param bool $replace
|
|
* @param string|null $pathname
|
|
*/
|
|
function p($data, $replace = false, $pathname = NULL) {
|
|
is_null($pathname) && $pathname = RUNTIME_PATH . date('Ymd') . '.txt';
|
|
$str = (is_string($data) ? $data : (is_array($data) || is_object($data)) ? print_r($data, TRUE) : var_export($data, TRUE)) . "\n";
|
|
$replace ? file_put_contents($pathname, $str) : file_put_contents($pathname, $str, FILE_APPEND);
|
|
}
|
|
|
|
/**
|
|
* 安全URL编码
|
|
* @param array $data
|
|
* @return string
|
|
*/
|
|
function encode($data) {
|
|
return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode(serialize($data)));
|
|
}
|
|
|
|
/**
|
|
* 安全URL解码
|
|
* @param string $string
|
|
* @return string
|
|
*/
|
|
function decode($string) {
|
|
$data = str_replace(array('-', '_'), array('+', '/'), $string);
|
|
$mod4 = strlen($data) % 4;
|
|
($mod4) && $data .= substr('====', $mod4);
|
|
return unserialize(base64_decode($data));
|
|
} |