// $low and $high have to be integers function BinarySearch( $array, $key, $low, $high ) { if( $low > $high ) // termination case { return -1; } $middle = intval( ( $low+$high )/2 ); // gets the middl
对指定的关键词进行替换处理,在html页面上高亮显示 function highlight($sString, $aWords) { if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) { return false; } $sWords = implode ('|', $aWords); return preg_
很多网站上的投票依据是ip地址,不同的ip地址一天可投票一次 下面的代码就是利用curl扩展来伪造ip地址 达到无限制投票; $times = $_POST['times']; //投票次数 $url = $_POST['url']; //投票地址[某个选手下方投票按钮的链接] while ($times) { $ip1 = 'X-FORWARDED-FOR:'.rand(115,225).'.'
// local file that should be send to the client $local_file = 'test-file.zip'; // filename that the user gets as default $download_file = 'your-download-name.zip'; // set the download rate limit (=> 2
class Ender{ private $enkey;//加密解密用的密钥 //构造参数是密钥 public function __construct($key=''){ if(!$key){ $this->enkey=$key; } } //设置密钥 public function set_key($key){ $this->enkey=$key; } private function key
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut elit id mi ultricies adipiscing. Nulla facilisi. Praesent pulvinar, sapien vel feugiat vestibulum, nulla dui pretium orci, n
/* ** Connect to database: */ // Connect to the database (host, username, password) $con = mssql_connect('localhost','admin','foo') or die('Could not connect to the server!'); // Select a database: ms
可解压缩zip文件。它有两个参数:压缩文件的路径、目标文件的路径。 function unzip_file($file, $destination) { // create object $zip = new ZipArchive() ; // open archive if ($zip->open($file) !== TRUE) { die ('Could not open archive')
一分钟内“刚刚”一小时内“* 分钟前”今天内“今天 小时:分钟”昨天内“昨天 小时:分钟“大于2天”年-月-日 小时:分钟“ //格式化时间 function format_date($beforetime) { $time= time() - $beforetime; $today=strtotime(date("M-d-y",mktime(0,0,0,date("m"),date("d"),d
//返回一个时间段内所有月份 传时间戳 function monthList($start,$end){ if(!is_numeric($start)||!is_numeric($end)||($end<=$start)) return ''; $start=date('Y-m',$start); $end=date('Y-m',$end); //转为时间戳 $start=strtotime($s
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 <java\0script> // note that you have to
/* function:二维数组按指定的键值排序 $array=array( 0=>array('id'=>8,'username'=>'phpernote'), 1=>array('id'=>9,'username'=>'com'), 2=>array('id'=>5,'username'=>'www') ); 现在需要将这个二维数组按id升序排列,则: array_sort($array,'i
一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。如果你希望它们强制被下载,也没问题。可以使用以下代码: function downloadFile($file){ $file_name = $file; $mime = 'application/force-download'; header('Pragma: public'); // required header('Exp
/** * 过滤字符串中的html标签 * * @param string $string 待转换的字符串 * @return string */ static public function strip_tags ( $string ) { return strip_tags ( $string ); }
/** * The generic DB access Class, Entry of all DB Access * Only PG is supported -- 201210 * * @author Anthony * 2010-2012 reserved */ class DB { // Query types const SELECT = 1; const INSERT = 2; con
/** * 图片缩放水印类 * */ class cls_photo { protected $waterrate = 0.2; //水印图标在图片上的比例 protected $width = 300; //缩略图默认宽度 protected $height = 200; //缩略图默认高度 protected $padding = 5; //水印图到边的距离 protected $water_
/********************** *@filename - path to the image *@tmpname - temporary path to thumbnail *@xmax - max width *@ymax - max height */ function resize_image($filename, $tmpname, $xmax, $ymax) { $ext
function show_page($count,$page,$page_size) { $page_count = ceil($count/$page_size); //计算得出总页数 $init=1; $page_len=7; $max_p=$page_count; $pages=$page_count; //判断当前页码 $page=(empty($page)||$page<0)?1:$p
KEY 是之前定义的常量 Mcrypt::encrypt(); Mcrypt::decrypt(); defined('ROOT') or exit('Access Denied'); class Mcrypt{ public static function encrypt($code){ return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_25
<? /** * 验证码类 * @author firerat * @email lukai_rat@163.com * @time Feb 16 2011 15:28 * @lastmodify Feb 16 2011 15:28 */ class verifycode{ //image source private $im; //图片宽度 private $w; //图片高度 private