php随机生成易于记忆的密码 代码段

function random_readable_pwd($length=10){ // the wordlist from which the password gets generated // (change them as you like) $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,'; $words .= 'green,blu

eb5y 2015-01-06   1097   0
PHP  

字符串加密解密PHP 代码段

<? class cryption { function en($str,$key) { $ret=''; $str = base64_encode ($str); for ($i=0; $i<=strlen($str)-1; $i++){ $d_str=substr($str, $i, 1); $int =ord($d_str); $int=$int^$key; $hex=strtoupper(

pbd4 2015-01-17   1106   0
PHP  

php自定义urlencode,urldecode函数 代码段

//配合JavaScript的ajaxObject函数, 对字串进行转码. function ajax_encode($str){ $patern = array("/%/","/=/","/&/");// % 必须是第一个项, 替换是按项的顺序进行的. $rp = array("%25","%26","%3D"); return preg_replace($patern,$rp,$str); }

6e72 2015-01-22   1182   0
PHP  

PHP实现导出Excel文件通用方法 代码段

/** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@param $filename 下载的文件名 *@examlpe $stu = M ('User'); $arr = $stu -> select(); exportexcel($arr,array('

lpki124 2015-03-03   1029   0
PHP  

PHP实现下载图片的通用方法 代码段

function getPicture($url,$pictureName){ if ($url == "") return false; //获取图片的扩展名 $info = getimagesize($url); $mime = $info['mime']; $type = substr(strrchr($mime,'/'), 1); //不同的图片类型选择不同的图片生成和保存函数 switc

lpki123 2015-03-03   1047   0
PHP  

php生成缩略图代码 代码段

/********************** *@filename - path to the image *@tmpname - temporary path to thumbnail *@xmax - max width *@ymax - max height */ function resize_image($filename, $tmpname, $xmax, $ymax) { $ext

phpde 2015-03-17   707   0
PHP  

php计算页面执行时间代码 代码段

<? class c_Timer { var $t_start = 0; var $t_stop = 0; var $t_elapsed = 0; function start() { $this->t_start = microtime(); } function stop() { $this->t_stop = microtime(); } function elapsed() { if ($

phpde1 2015-03-17   647   0
PHP  

PHP获取2个日期之间的天数 代码段

function daysbetweendates($date1, $date2){ $date1 = strtotime($date1); $date2 = strtotime($date2); $days = ceil(abs($date1 - $date2)/86400); return $days; }

n6bg 2015-04-29   851   0
PHP  

PHP抽奖程序概率算法 代码段

//概率算法,6个奖项 $prize_arr = array( '0' => array('id'=>1,'prize'=>'iphone6','v'=>1), '1' => array('id'=>2,'prize'=>'数码相机','v'=>5), '2' => array('id'=>3,'prize'=>'音箱设备','v'=>10), '3' => array('id'=>4,'priz

jopen 2015-08-24   1667   0
算法  

查找页面中所有链接的PHP代码 代码段

function get_links($link) { $html = file_get_contents($link); $html = str_replace("\n", "", $html); $html = preg_replace('/<a/i', "\n<a", $html); $html = preg_replace('/<\/a>/', "</a>\n", $html); preg

en9 2014-12-30   1741   0
PHP  

PHP获取时间段代码 代码段

$start_time = ''; $end_time = ''; switch ($type) { case 'thisWeek'://本周 $start_time = date("Y-m-d H:i:s",strtotime("-0 week Monday")); $end_time = date("Y-m-d H:i:s",strtotime("-0 week Sunday")); brea

pkiek123 2014-12-30   1060   0
PHP  

php防御XSS攻击 代码段

function remove_xss($val) { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as // note that you have to handle splits w

b4c2 2015-01-13   2354   0
PHP  

PHP 获取客户端ip 代码段

function get_client_ip() { if (getenv("HTTP_CLINET_IP") && strcasecmp(getnenv("HTTP_CLINET_IP")), "unknown") { $ip = getenv("HTTP_CLINET_IP"); } else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(g

ef4w 2015-02-09   1262   0
PHP  

PHP实现压缩html的函数 代码段

function compress_html($string) { $string = str_replace("\r\n", '', $string); //清除换行符 $string = str_replace("\n", '', $string); //清除换行符 $string = str_replace("\t", '', $string); //清除制表符 $pattern = arr

lpki123 2015-03-03   1169   0
PHP  

php实用获取远程图片的通用方法 代码段

function auto_save_image($body){ $img_array = explode('&',$body); /*$img_array = array(); preg_match_all("/(src)=[\"|\'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))[\"|\'| ]{0,}/isU", $body, $img_arr

lpki124 2015-03-03   785   0
PHP  

PHP实现整个目录的拷贝功能 代码段

function copy_dir($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { copy_di

lpki123 2015-03-03   882   0
PHP  

PHP防XSS 防SQL注入的代码 代码段

作为开发人员时刻要记住一句话,永远不要相信任何用户的输入!很多时候我们的网站会因为我们开发人员写的代码不够严谨,而使网站受到攻击,造成不必要的损失!下面介绍一下如何防止SQL注入! 这里提供了一个函数,用来过滤用户输入的内容!使用POST传值的时候,可以调用这个函数进行过滤! /** * 过滤参数 * @param string $str 接受的参数 * @return string */ sta

jopen 2015-04-22   1284   0
PHP  

PHP生成指定随机字符串的方法 代码段

一个简单的函数,没有对生成的内容作强制设定。所以在生成的字符串长度较少的时候,会出现没有指定类型字符的情况。当然,修改起来也很简单,这里就不做添加了。 /** * @param string $type * @param $length * @return string */ function randomString($type="number,upper,lower",$length){ $v

ngww 2015-04-23   1113   0
PHP  

PHP删除目录及目录下所有文件的方法 代码段

删除目录及目录下的所有文件 //循环删除目录和文件函数 function delDirAndFile($dirName){ if($handle = opendir("$dirName")){ while(false!==($item = readdir($handle))){ if($item != "." && $item != ".." ){ if(is_dir("$dirName/$ite

n6bg 2015-04-29   1329   0
PHP  

php通过imagick库把PDF转成PNG格式 代码段

function pdf2png($PDF,$Path){ if(!extension_loaded('imagick')){ return false; } if(!file_exists($PDF)){ return false; } $IM = new imagick(); $IM->setResolution(120,120); $IM->setCompressionQuality(100

xm52 2015-05-08   1108   0
PHP  
1 2 3 4 5 6 7 8 9 10