php生成excel文档<? header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=test.xls"); echo "test1t"; echo "t……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1162浏览 0评论2622个赞
php获取访问者的操作系统信息<? function osinfo() { $os=""; $Agent = $GLOBALS["HTTP_USER_AGENT"]; if (eregi('win',$Agent) && strpos($Agent, '……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2729浏览 0评论1638个赞
php删除指定的目录,本代码会递归删除子目录<?php/** * Delete a file, or a folder and its contents (recursive algorithm) * * @author Aidan Lister <aidan@php.net> * @version 1.0……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2309浏览 0评论1031个赞
这段代码可以自动根据post数组的键值创建同名变量,这个功能使用非常方便,不用提前声明变量<?php$expected=array('username','age','city','street');foreach($expected as $key){ ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1506浏览 0评论2632个赞
php简单截断字符串函数,如果截断在字符串后自动加上省略号function short($txt,$size){ $short = $size - 3; if(strlen($txt) > $size){ $data = substr( $txt, 0, $short )."..."; ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2420浏览 0评论2879个赞
将HTML表格的每行每列转为数组,采集表格数据<? function get_td_array($table) { $table = preg_replace("'<table[^>]*?>'si","",$table); //oSPHP.COM.C……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3107浏览 0评论242个赞
php获取当前urlfunction curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; i……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2319浏览 0评论951个赞
返回字符串中的所有单词 $distinct=true 去除重复<? function split_en_str($str,$distinct=true) { preg_match_all('/([a-zA-Z]+)/',$str,$match); if ($distinct == true……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1686浏览 0评论1190个赞
php将12小时制转换成24小时制,输入格式为:02:30:00 pm 转换成:14:30:00<?phpfunction to_24_hour($hours,$minutes,$seconds,$meridiem){ $hours = sprintf('%02d',(int) $hours); $minut……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2694浏览 0评论1139个赞
javascriipt通过当前时间解决GET和POST的缓存问题在postUrl后面添加当前时间为参数,可以有效的解决缓存问题因为每次提交的url地址都是不同的var currentTime = new Date();var n = currentTime.getTime();postUrl = "http://www.example.c……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1400浏览 0评论1999个赞
Sum all elements of a bidimensional or multi-dimensional array with an assigned key/** * sum values in array * * @param array $arr * @param string [optional]$index * @retur……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1253浏览 0评论648个赞
简单的PHP框架,实现antoload,viewEngine,有兴趣学写MVC框架的可以看看这篇文章: http://my.oschina.net/u/131802/blog/82016 这个很适合初学者对框架的认识 index.php 入口文件<?php……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2395浏览 0评论1830个赞
360提供的php防注入代码<?php //Code By Safe3 function customError($errno, $errstr, $errfile, $errline) { echo "<b>Error number:</b> [$errno],error on line $……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2935浏览 0评论1942个赞
根据给定的数字查找其因数的高效C++代码//Algorithm derived from the method described here://http://mathschallenge.net/index.php?section=faq&ref=number/number_of_divisorsint mathTools::numFac……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2706浏览 0评论403个赞
php实现的ssh api类,主要用来通过ssh传输文件class SshApi extends BaseObject{ public $session = null; public $authenticated = false; public function __construct(){ } p……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1641浏览 0评论2891个赞
php遍历目录的代码<?php function myscandir($pathname){ foreach( glob($pathname) as $filename ){ if(is_dir($filename)){ myscandir($filename.……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1236浏览 0评论2451个赞
简单的php正则校验email地址的函数<?php /* If you won't use filter_var() you should use this instead */ function isEmail($email) { if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-z……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1628浏览 0评论2705个赞
Android通过HttpClient执行post请求public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = n……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1774浏览 0评论203个赞
指定原始字符串,给定开始和结尾字符串,获得这两个字符串之间的子字符串的php函数/** * Returns the substring between two strings, delimiters not included * @param string $string Haystack * @param string $start Start……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2538浏览 0评论2985个赞
一个文件大小单位格式化的php函数,如 echo format_size(filesize(“fichier”)); 输出:13,37 Ko<?php/* Use : echo format_size(filesize("fichier"));Example result : 13,37 Ko */……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2940浏览 0评论2511个赞
php打水印函数function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2151浏览 0评论927个赞
php给一组指定的关键词添加span标签,高亮突出显示关键词// Example use: $spanned = codeWords($string_containing_keywords);// My site: andrew.dx.am// Using colour==blue, but different arrays of words an……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1482浏览 0评论2958个赞
php Query posts and cache the query$bandeau_post = get_transient('top1_bandeau_post'); if (!is_array($bandeau_post) || count($bandeau_post)==0) { ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1683浏览 0评论1613个赞
php从map删除指定的元素并返回一个新的mapval origMap = Map("key1" -> "something", "key2" -> "else");val myMap = origMap - "key1";//myMap……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3637浏览 0评论288个赞
与大多数流行的 Web 服务如 Twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。$json_string='{"id":1,"name":"foo","email":"f……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1534浏览 0评论2886个赞
php删除整个目录的代码/******@dir - Directory to destroy*@virtual[optional]- whether a virtual directory*/function destroyDir($dir, $virtual = false){ $ds = DIRECTORY_SEPARATOR;……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2296浏览 0评论643个赞
php将字符串中的url转换成超级链接function makeClickableLinks($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1">……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1737浏览 0评论2711个赞
php解析xml数据代码//xml string$xml_string="<?xml version='1.0'?><users> <user id='398'> <name>Foo</name> <em……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2629浏览 0评论1029个赞
php常用数组操作:追加、合并、连接代码演示 在处理php数组经常需要合并、追加、连接数组合并数组array_merge()函数将数组合并到一起,返回一个联合的数组。所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加写法:array array_merge (a……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2085浏览 0评论1373个赞
php调整图片尺寸的代码/***********************@filename - path to the image*@tmpname - temporary path to thumbnail*@xmax - max width*@ymax - max height*/function resize_image($filen……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2508浏览 0评论2119个赞
php分页代码/*分页的核心就2点1.计算总页数2.计算偏移*/// 数据集大小$count = 10;// 计算页数,如果没有GET参数则置为1$page = isset($_GET['page']) ? intval($_GET['page']) : 1;// 如果页数小于1或者大于数据集总……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3037浏览 0评论337个赞
支持多编码字符串截取php函数function cutstr($str, $start=0, $length, $charset="utf-8", $suffix=""){ if(function_exists("mb_substr")){ return mb_sub……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2753浏览 0评论2691个赞
公司一个项目需要上传图片,一开始同事将图片上传后结合当前主机拼成了一个绝对的URL(http://192.168.1.1:888/m/getimg?filename=xxx.jpg)由于同时给手机终端提供接口,在手机终端会引起一些bug,改完代码后要求将以前的uri替换成相对的URL(/m/getimg?filename=xxx.jpg),由于图片是用img……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2039浏览 0评论1249个赞
做了一个在线代码高亮的项目,因为写的Gtalk群Bot需要这个功能支持,贴到第三方怕被人给封,所以干脆想自己写一个,强大的Python一如既往没让我失望,一个强大的Pygments模块可以对多种(很多)语言进行代码高亮转自:http://www.linuxzen.com/index.php/archives/377 ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1195浏览 0评论199个赞
php给MD5算法增加一些干扰加强密码安全性function md123($sstr){$md_asc=”";$mds=md5(“qwEqw”.$sstr.”2ddsdf”);$mds=md5(“rtrTtyr”.$mds.”zcv34r”);for($i=1;$i< strlen($mds);$i++){$md_asc.=……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1362浏览 0评论646个赞
一个简单的php缓存类<?php/** * Class Cache * * @author Koen Ekelschot * @license WTFPL */class Cache { private $cachedFile; public function __construct($identifier) { ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2187浏览 0评论128个赞
php检测字符串中是否包含外部链接/** * is_external_link 检测字符串是否包含外链 * @param string $text 文字 * @param string $host 域名 * @return boolean false 有外链 true 无外链 * http://blog.qita.inf……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1855浏览 0评论616个赞
php自定义函数检测是否是utf8编码其实php有一个内置函数可以用:mb_detect_encodingfunction is_utf8($string){ return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1491浏览 0评论2327个赞
php简单的多字节字符串翻转<?phpfunction mb_strev ($string, $encoding = null) { if ($encoding === null) { $encoding = mb_detect_encoding($string); } $length = mb_strlen($stri……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3137浏览 0评论2674个赞
php 获取客户端的ip、地理信息、浏览器信息、本地真实ip<?php // 作用取得客户端的ip、地理信息、浏览器http://blog.qita.in class get_gust_info { ////获得访客浏览器类型 function GetBrowser(){ if(!empty($_SERVER[……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2571浏览 0评论206个赞
简单的php日志写入函数function log( $logthis ){file_put_contents('logfile.log', date("Y-m-d H:i:s"). " " . $logthis. "\r\n", FILE_APPEND | LOCK_EX……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2458浏览 0评论2663个赞
有些摄影师喜欢把图片的标题,内容,关键词等用photoshop直接写入图片文件里面。 用以下代码可以读取。$image_info = array();$size = getimagesize('图片文件.jpg', $info);if(isset($info['APP13'])){ $iptc = ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3109浏览 0评论728个赞
比如秒数时间很长,可以通过这段代码转换成几年几月几日的形式$time = time() - $time; $points = array( 'year' => 31556926, 'month' => 2629743,……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1552浏览 0评论2017个赞
php自带的rmdir,只能删除空目录,这个rrmdir就可以递归删除目录及目录下的所有文件,不过使用起来要小心哦,不要把所有文件都删了。function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $obj……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1298浏览 0评论2296个赞
php gzinflate和base64_decode加密解密<?php function encode_file_contents($filename) { $type=strtolower(substr(strrchr($filename,’.'),1)); if(’php’==$type && is_file……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1386浏览 0评论1556个赞