php 不重复的随机数

php 不重复的随机数

/** * 不重复的随机数 * 用作采集时的文件,批量下载进防止文件重复 */ function random_id() { $chars = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $chars_cnt = strlen($chars)-1; $id = ''; for ($i = 0; $i < 5; ++$i) { $id .= $chars[rand(0, $chars_cnt)]; } ...

PHP 2021-02-28 PM 143℃ 0条
php 处理禁用HTML但允许换行的内容

php 处理禁用HTML但允许换行的内容

/*** 处理禁用HTML但允许换行的内容 * * @access public * @param string $msg 需要过滤的内容 * @return string */ function TrimMsg($msg) { $msg = trim(stripslashes($msg)); $msg = nl2br(htmlspecialchars($msg)); $msg = str_replace(" ","&nbsp;&nbsp;",$msg); return a...

PHP 2021-02-28 PM 134℃ 0条
php 获得某天前的时间戳

php 获得某天前的时间戳

//获得某天前的时间戳 function getxtime($day) { $day = intval($day); return mktime(23,59,59,date("m"),date("d")-$day,date("y")); }

PHP 2021-02-28 PM 133℃ 0条
php 生成字母前缀

php 生成字母前缀

//生成字母前缀 function letter_first($s0) { $firstchar_ord=ord(strtoupper($s0{0})); if (($firstchar_ord>=65 and $firstchar_ord<=91)or($firstchar_ord>=48 and $firstchar_ord<=57)) return $s0{0}; //$s = iconv("utf-8", "gbk//ignore", $s0); ...

PHP 2021-02-28 PM 136℃ 0条
PHP escape unescape

PHP escape unescape

/ PHP escape /public static function escape($str) {preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(ord($v[0]) < 128) { $ar[$k] = rawurlencode($v); } else { $ar[$k] = "%u".bin2hex(iconv(NUll,"UCS...

PHP 2021-02-28 PM 111℃ 0条
php循环显示文件,返回array

php循环显示文件,返回array

//循环显示文件,返回array public static function dirAllFile($dirName) { // global $array; $array = array(); // util::pre_print_r($array); if ($handle = opendir("$dirName")) { while (false !== ( $item = readdir($handle) )) { ...

PHP 2021-02-28 PM 122℃ 0条
php循环删除目录和文件函数

php循环删除目录和文件函数

//循环删除目录和文件函数 public static function delDirAndFile($dirName, $delDir = 0) { if ($handle = opendir("$dirName")) { while (false !== ( $item = readdir($handle) )) { if ($item != "." && $item != ".."...

PHP 2021-02-28 PM 114℃ 0条
php 截取字符串

php 截取字符串

/**$sourcestr 是要处理的字符串$cutlength 为截取的长度(即字数) */static function cut_str($sourcestr, $cutlength, $type = true){$returnstr = ''; $i = 0; $n = 0; $str_length = strlen(trim($sourcestr)); //字符串的字节数 while (($n < $cutlength) and ($i <= $str_length)) { $temp_str = substr($sourcestr, $i, 1); ...

PHP 2021-02-28 PM 107℃ 0条
php 下载到本地

php 下载到本地

/**下载到本地 */ static function httpcopy($url, $file = "", $timeout = 600) { if (empty($file)) return false; $dir = pathinfo($file, PATHINFO_DIRNAME); !is_dir($dir) && @mkdir($dir, 0755, true); $url = str_replace(" &q...

PHP 2021-02-28 PM 113℃ 0条
php 判断是否为utf8字符串

php 判断是否为utf8字符串

/** * 判断是否为utf8字符串 * @parem $str * @return bool 180it.com */ function is_utf8($str) { if ($str === mb_convert_encoding(mb_convert_encoding($str, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) { return true; ...

PHP 2021-02-28 PM 99℃ 0条
php 检查路径是否存在

php 检查路径是否存在

/**检查路径是否存在@parem $path@return bool*/function path_exists($path){$pathinfo = pathinfo($path . '/tmp.txt'); if (!empty($pathinfo ['dirname'])) { if (file_exists($pathinfo ['dirname']) === false) { if (mkdir($pathinfo ['dirname'], 0777, true) === false) { return ...

PHP 2021-02-28 PM 80℃ 0条