日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

自己写的几个常用到的函数

發布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自己写的几个常用到的函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<?php

????? /*

????? ?*?? 生成指定數量和指定字符串生成隨機字符串

????? ?*?? @param int $len 獲取隨機字符的個數

????? ?*?? @param string $range 指定在該字符串中獲取隨機字符

????? */

????? function randomString($len,$range=''){

?????????? if($range == ''){

???????????????? $str = '0123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ';

?????????? }else{

???????????????? $str = $range;

?????????? }

?????????? $rand_str = '';

?????????? for($i=0;$i<$len;$i++){

???????????????? $rand_str .= $str[rand(0,strlen($str)-1)];

?????????? }

?????????? return $rand_str;

????? }

????? /*

????? ?* 遍歷文件夾

????? ?* @param string $path 路徑

????? */

????? function getListDir($path){//可嘗試添加按深度獲取

?????????? $file = array();

?????????? $dir = dir($path);

?????????? while($handle = $dir->read()){

???????????????? if($handle != '.' && $handle != '..'){

????????????????????? if(is_dir($dir->path.'\\'.$handle)){

??????????????????????????? $file[$handle] = getListDir($dir->path.'\\'.$handle);

????????????????????? }else{

??????????????????????????? $file[] = $handle;

????????????????????? }

???????????????? }

???????????????? $y++;

?????????? }

?????????? return $file;

????? }

????? /*

????? ?* 獲取用戶的ip地址????

????? */

????? function getIp(){

?????????? $ip = '';

?????????? if(isset($_SERVER['HTTP_CLIENT_IP'])){

???????????????? $ip = $_SERVER['HTTP_CLIENT_IP'];

?????????? }elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){

???????????????? $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];

?????????? }else{

???????????????? $ip = $_SERVER['REMOTE_ADDR'];

?????????? }

?????????? return $ip;

????? }

?

????? /*

????? ?* 取后綴的方法有很多,這只是其中一種

????? ?* @param string $filename 文件名

????? */

????? function getExt($filename){

?????????? $arr = explode('.',$filename);

?????????? $ext = $arr[count($arr)-1];

?????????? return $ext;

????? }

?

?

????? /*

????? ?* 記錄日志(這個和老版本的shopNc的記錄方式相同)

????? ?* @param string $txt 待寫入的日志內容

????? ?* @param string $base_path 存放日志文件的路徑

????? */

????? function log($txt,$base_path){

?????????? header("Content-type:text/html; charset=utf-8");

?????????? if(isset($base_path)){

???????????????? $path = $base_path;

?????????? }else{

???????????????? $path = dirname(__FILE__);

?????????? }

?????????? $filename = data("Y-m-d").'.log';

?????????? $filepath = $path.'\\'.$filename;

?????????? $content = data("Y-m-d H:i:s").':'.$txt.PHP_EOL;

?????????? if(file_put_contents($filepath,$content,FILE_APPEND)){

???????????????? return true;

?????????? }else{

???????????????? return false;

?????????? }

????? }

?????

???

?

轉載于:https://www.cnblogs.com/trblog/p/5604165.html

總結

以上是生活随笔為你收集整理的自己写的几个常用到的函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。