/** 数字化隐私输出
* @param $string
* @param int $start 前面显示位数
* @param int $end 后面显示位数
* @param string $re
* @return bool|string
*
function number_private($string, $start = 4, $end = 4, $re = '*'){
if (empty($string)){
return false;
}
$length = strlen($string);
$start = abs($start);
$end = abs($end);
if($length <= $start + $end){
return $string;
}
$start_str = substr($string, 0, $start);
$end_str = substr($string, -1 * $end);
$middle_str = str_repeat($re, $length - $start - $end);
return $start_str . $middle_str . $end_str;
}
/或者函数
substr_replace($phone, '****', 3, 4);
//计算生日年龄
function calcAge($birthday) {
$age = 0;
if(!empty($birthday)){
$age = strtotime($birthday);
if($age === false){
return 0;
}
list($y1,$m1,$d1) = explode("-",date("Y-m-d", $age));
list($y2,$m2,$d2) = explode("-",date("Y-m-d"), time());
$age = $y2 - $y1;
if((int)($m2.$d2) < (int)($m1.$d1)){
$age -= 1;
}
}
return $age;
}
des加密需要开启php的openssl扩展
/**
* des-ecb加密
* @param string $data 要被加密的数据
* @param string $key 加密密钥(64位的字符串)
*/
function des_ecb_encrypt($data, $key){
return openssl_encrypt ($data, 'des-ecb', $key);
}
/**
* des-ecb解密
* @param string $data 加密数据
* @param string $key 加密密钥
*/
function des_ecb_decrypt ($data, $key){
return openssl_decrypt ($data, 'des-ecb', $key);
}
检测是不是手机端登陆
function isMobile() {
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset($_SERVER['HTTP_VIA'])) {
// 找不到为flase,否则为true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
// 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = array('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile');
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset ($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
<script type="text/javascript">
function uaredirect(murl){
try {
if(document.getElementById("xuhuiwap") != null){
return;
}
var urlhash = window.location.hash;
if (!urlhash.match("fromapp")){
if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
location.replace(murl);
}
}
} catch(err){
}
}
uaredirect("/h5/");
</script>
下载文件
<?php
$file_url=$_SERVER['DOCUMENT_ROOT'].'/sfj2017102101.apk';
$file_name=basename($file_url);
$file_type=explode('.',$file_url);
$file_type=$file_type[count($file_type)-1];
$file_name=trim($new_name=='')?$file_name:urlencode($new_name);
$file_type=fopen($file_url,'r'); //打开文件
//输入文件标签
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($file_url));
header("Content-Disposition: attachment; filename=".$file_name);
//输出文件内容
echo fread($file_type,filesize($file_url));
fclose($file_type);
?>
下载图片
<?php
$input = file_get_contents('https://mmbiz.qpic.cn/mmbiz_jpg/KlYj89pYNRlFjiaEiawmHAf1tEdHcUhciaTNG1muK5JRxmO24YpFuRj1AB74OeJjWrdc9P3icxy6sjRgAUhib5QiaOxg/640?wx_fmt=jpeg');
$f = fopen('test.png','a+');
fwrite($f,$input."\r\n");die;
?>
记录两个绘制图表的网址
https://www.highcharts.com.cn/docs/column-and-bar-charts
https://echarts.baidu.com/examples/#chart-type-line
获取附近商家的接口
http://api.map.baidu.com/place/v2/search?query=%E4%BC%81%E4%B8%9A&location=39.915,116.404&radius=2000&output=json&ak=OmXe4ttG8LT2XRXeKKd5PoURO9as7E9T
修改apache路径
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(.*\.)?xingshi.xuhuinet.com$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1
</IfModule>
public function test(){
$url = "https://api.verification.jpush.cn/v1/web/verify";
$str = base64_encode("wxeb2b41297580b84c:3fd7ed0782f78c3e0d7f8fc883a10973");
$headers[] = "Accept:application/json";
$headers[] = "Authorization: Basic ".$str;
$result = $this->post_curl($url,1,$headers);
dump($result);
dump($headers);
}
public function post_curl($url,$data,$headers){
// 初始化一个 cURL 对象
$curl = curl_init();
// 设置你需要抓取的URL
curl_setopt($curl, CURLOPT_URL,$url);
//必须加这个,不加不好使(不多加解释,东西太多了)
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//对认证证书进行检验
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if (!empty($data)){//post方式,否则是get方式
//设置模拟post方式
curl_setopt($curl,CURLOPT_POST,1);
//传数据,get方式是直接在地址栏传的,这是post传参的解决方式
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);//$data可以是数组,json
}
// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。1是保存,0是输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $headers );
// 运行cURL,请求网页
$output = curl_exec($curl);
// 关闭URL请求
curl_close($curl);
return $output;
}
获取三天前的时间: $mytime= date("Y-m-d H:i:s", strtotime("-3 day"));
获取前一个月的时间:$mytime= date("Y-m-d H:i:s", strtotime("-1 month"));
php截取指定两个字符之间字符串
$str = '90K800B2CD (LENOVO)';
$start = '(';
$end = ')';
$str = substr($str, strlen($start)+strpos($str, $start),(strlen($str) - strpos($str, $end))*(-1));
用于请求微信接口获取数据
function get_by_curl($url,$post = false){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($post){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 首字母头像
* @param $text
* @return string
*/
function letter_avatar($text)
{
$total = unpack('L', hash('adler32', $text, true))[1];
$hue = $total % 360;
list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
$bg = "rgb({$r},{$g},{$b})";
$color = "#ffffff";
$first = mb_strtoupper(mb_substr($text, 0, 1));
$src = base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" dominant-baseline="central">' . $first . '</text></svg>');
$value = 'data:image/svg+xml;base64,' . $src;
return $value;
}
/**
* 记录日志文件
* @param $content:内容
* @param $filename:文件名
* @param $dirname:文件夹名,用于区分不同的日志分类
* */
function writeLog($content='', $filename='',$dirname='')
{
if (! $content)
{
return false;
}
$str = substr(getcwd (),0,-3);
$dir = $str.'runtime\payLogs\' . $dirname;
if (! is_dir ( $dir ))
{
if (! mkdir ( $dir ))
{
return false;
}
}
if(!empty($filename))
{
$filename=iconv("UTF-8", "GB2312//IGNORE", $filename);
$filename = $dir . DIRECTORY_SEPARATOR . $filename . '.log';
}else {
$filename = $dir . DIRECTORY_SEPARATOR . date ('Ymd',time ()) . '.log';
}
$str = 'Time:'.date ( "Y-m-d H:i:s" )."\r\n".'内容:'. $content . "\r\n";
if (! $fp = @fopen ( $filename, "a" ))
{
return false;
}
if (! fwrite ( $fp, $str ))
return false;
fclose ( $fp );
return true;
}
```php
/**
* tp记录日志文件
* @param string $content:内容
* @param string $filename:文件名
* @param string $dirname:目录名,用于区分不同的日志分类
* @return bool
*/
function writeLog($content = '', $filename = 'log', $dirname = 'log') {
if (!$content) {
return false;
}
$content = json_encode($content,JSON_UNESCAPED_UNICODE);
$filename = date('YmdH').$filename.'_log';
$str = 'Time:' . date("Y-m-d H:i:s") . "\r\n" . '内容:' . $content . "\r\n";
$dir = root_path() .'/runtime/'. $dirname.'_log';
if (!is_dir($dir)) {
if (!mkdir($dir)) {
return false;
}
}
file_put_contents($dir.'/'.$filename,$str,FILE_APPEND);
}
/**
* 二维数组按指定的键值排序
* $array:数组
* $key:排序键值
* $type:排序方式
* */
function array_sort($arr, $keys, $type = 'desc')
{
$keysvalue = $new_array = array();
//先取出需要排序的键
foreach ($arr as $k => $v)
{
$keysvalue[$k] = $v[$keys];
}
//将键重新排序
if ($type == 'asc')
{
asort($keysvalue);
} else {
arsort($keysvalue);
}
reset($keysvalue);
//根据排序后的键顺序得到新的数组
foreach ($keysvalue as $k => $v)
{
$new_array[$k] = $arr[$k];
}
return $new_array;
}
//方法二
$check = array_column($arr, 'checked');
array_multisort($check, SORT_ASC, $arr);/*SORT_ASC - 默认。按升序排列(A-Z)SORT_DESC 按降序排列(Z-A)*/
后面的后期再补
```php
//先删除目录下的文件:
$dir = root_path().'public/strong/';
function deldir($dir) {
//先删除目录下的文件:
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
//删除当前文件夹:
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
//tp伪静态
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
//宝塔配置文件
server
{
listen 80;
listen 443 ssl http2;
server_name 网站域名;
index index.php index.html index.htm default.php default.htm default.html;
root tp项目绝对路径/public;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /www/server/panel/vhost/cert/域名/fullchain.pem;(证书绝对路径)
ssl_certificate_key /www/server/panel/vhost/cert/域名/privkey.pem;(证书绝对路径)
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-74.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/deertest.lu99.vip.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log /dev/null;
}
access_log /www/wwwlogs/日志;
error_log /www/wwwlogs/错误日志;
}