php打水印函数function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2071浏览 0评论1485个赞
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) 1201浏览 0评论2852个赞
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) 1945浏览 0评论2465个赞
php从map删除指定的元素并返回一个新的mapval origMap = Map("key1" -> "something", "key2" -> "else");val myMap = origMap - "key1";//myMap……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2084浏览 0评论659个赞
php删除整个目录的代码/******@dir - Directory to destroy*@virtual[optional]- whether a virtual directory*/function destroyDir($dir, $virtual = false){ $ds = DIRECTORY_SEPARATOR;……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1957浏览 0评论416个赞
与大多数流行的 Web 服务如 Twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。$json_string='{"id":1,"name":"foo","email":"f……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2359浏览 0评论599个赞
php将字符串中的url转换成超级链接function makeClickableLinks($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1">……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1371浏览 0评论2998个赞
php解析xml数据代码//xml string$xml_string="<?xml version='1.0'?><users> <user id='398'> <name>Foo</name> <em……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2643浏览 0评论151个赞
php常用数组操作:追加、合并、连接代码演示 在处理php数组经常需要合并、追加、连接数组合并数组array_merge()函数将数组合并到一起,返回一个联合的数组。所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加写法:array array_merge (a……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2434浏览 0评论2452个赞
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) 2075浏览 0评论1723个赞
php分页代码/*分页的核心就2点1.计算总页数2.计算偏移*/// 数据集大小$count = 10;// 计算页数,如果没有GET参数则置为1$page = isset($_GET['page']) ? intval($_GET['page']) : 1;// 如果页数小于1或者大于数据集总……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2087浏览 0评论1404个赞
支持多编码字符串截取php函数function cutstr($str, $start=0, $length, $charset="utf-8", $suffix=""){ if(function_exists("mb_substr")){ return mb_sub……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2629浏览 0评论2892个赞
公司一个项目需要上传图片,一开始同事将图片上传后结合当前主机拼成了一个绝对的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) 1224浏览 0评论2149个赞
做了一个在线代码高亮的项目,因为写的Gtalk群Bot需要这个功能支持,贴到第三方怕被人给封,所以干脆想自己写一个,强大的Python一如既往没让我失望,一个强大的Pygments模块可以对多种(很多)语言进行代码高亮转自:http://www.linuxzen.com/index.php/archives/377 ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2659浏览 0评论514个赞
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) 1361浏览 0评论996个赞
一个简单的php缓存类<?php/** * Class Cache * * @author Koen Ekelschot * @license WTFPL */class Cache { private $cachedFile; public function __construct($identifier) { ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1752浏览 0评论630个赞
php检测字符串中是否包含外部链接/** * is_external_link 检测字符串是否包含外链 * @param string $text 文字 * @param string $host 域名 * @return boolean false 有外链 true 无外链 * http://blog.qita.inf……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3161浏览 0评论2033个赞
php自定义函数检测是否是utf8编码其实php有一个内置函数可以用:mb_detect_encodingfunction is_utf8($string){ return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1785浏览 0评论2424个赞
php简单的多字节字符串翻转<?phpfunction mb_strev ($string, $encoding = null) { if ($encoding === null) { $encoding = mb_detect_encoding($string); } $length = mb_strlen($stri……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2722浏览 0评论704个赞
简单的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) 2489浏览 0评论1435个赞
php 获取客户端的ip、地理信息、浏览器信息、本地真实ip<?php // 作用取得客户端的ip、地理信息、浏览器http://blog.qita.in class get_gust_info { ////获得访客浏览器类型 function GetBrowser(){ if(!empty($_SERVER[……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2992浏览 0评论2163个赞
有些摄影师喜欢把图片的标题,内容,关键词等用photoshop直接写入图片文件里面。 用以下代码可以读取。$image_info = array();$size = getimagesize('图片文件.jpg', $info);if(isset($info['APP13'])){ $iptc = ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2559浏览 0评论524个赞
比如秒数时间很长,可以通过这段代码转换成几年几月几日的形式$time = time() - $time; $points = array( 'year' => 31556926, 'month' => 2629743,……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2025浏览 0评论1066个赞
php自带的rmdir,只能删除空目录,这个rrmdir就可以递归删除目录及目录下的所有文件,不过使用起来要小心哦,不要把所有文件都删了。function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $obj……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1349浏览 0评论2127个赞
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) 2459浏览 0评论1641个赞
php中文繁体和简体相互转换函数下面的代码用到了繁体和简体字库对照表<?phpclass utf8_chinese{ private $utf8_gb2312; private $utf8_big5; private $data; public function __const……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1784浏览 0评论2527个赞
通过python post提交数据的代码演示转自:http://blog.csdn.net/mypc2010# -*- coding: cp936 -*-import urllib2import urllibdef postHttp(name=None,tel=None,address=None, price=Non……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2380浏览 0评论1312个赞
Android下PreferenceActivity使用示例 MainActivity如下:package cn.testpreferenceactivity;import android.content.SharedPreferences;import android.os……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2083浏览 0评论479个赞
php简单代码实现无限分类树形列表转自:http://blog.csdn.net/shangxiaoxue/article/details/8463193$items = array( 1 => array('id' => 1, 'pid' => 0, 'name'……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1652浏览 0评论2835个赞
简单的php ubb转换代码[b]test[/b][url=http://blah.com]blah[/url] will become:<strong>test</strong><a href="http://b……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1597浏览 0评论2447个赞
php按字符截取中文并保证无乱码的方法<?php//$str 待截取的字符串//$len 截取的字符个数//$chars 已经截取的字符数//$res 保存的字符串//$chars 保存已经截取的字符串个数//$offset 截取的偏移量//$length 字符串的字节数//若$len>$str的字符个数,造成无谓的wh……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1998浏览 0评论209个赞
这段代码的时间复杂度为O(n)来源:http://blog.csdn.net/zinss26914/article/details/8032361<?php function JudegSortArray($array) { if ($array [0] > $array [1]) { $flag = 1……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2053浏览 0评论918个赞
php 找出数组中的重复数据转自:http://blog.csdn.net/zinss26914/article/details/8030618 (1)利用php提供的函数,array_unique和array_diff_assoc来实现<?php function Fe……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2180浏览 0评论2315个赞
PHP限制IP访问 只允许指定IP访问 允许*号通配符过滤IP转自:http://blog.csdn.net/yw5201314/article/details/8467525/** * 检测访问的ip是否为规定的允许的ip * Enter description here ... */function check_ip(){ $ALLOWE……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2958浏览 0评论465个赞
一个php编写的斐波那契数列代码片段 斐波那契数列(Fibonacci Sequence),又称黄金分割数列,指的是这样一个数列:1、1、2、3、5、8、13、21、……在数学上,斐波纳契数列以如下被以递归的方法定义:F0=0,F1=1,Fn=F(n-1)+F(n-2)(n>=2,n∈N*)。我用递归和迭代两种方法实现了斐波那契数列/** * De……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2898浏览 0评论304个赞
php实现字符串翻转的代码<?phpheader("content-type:text/html;charset=utf-8"); /**此函数的作用是反转中文字符串mb_strlen() 获取字符的长度mb_substr() 获取字符的单个元素krsort() 按照键值逆序排序数组implode() 将数组拼接……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1782浏览 0评论1421个赞
PHP中几个输出函数echo(),print(),print_r()的区别 echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量,做为一个字符串输出. 另一点区别在于echo 没有……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1242浏览 0评论2590个赞
php 判断客户端是否为手机移动设备判断客户端是否为手机移动设备 function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_agents = Array("240x320","acer&……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2715浏览 0评论1644个赞
解决php json_encode 函数中文乱码的问题解决以下问题json_encode 中文后的字符串不可阅读json_encode 多级数组中文乱码问题json_encode 数组中包含换行时错误问题json_encode 数组中键为中文的问题转自:http://blog.1dnet.net/?post=840function _encode($……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2246浏览 0评论1174个赞
php使用指定的编码导出mysql数据到csv的代码<?php ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1877浏览 0评论1623个赞
php上传图片客户端和服务器端代码演示 表单代码<form name="form1" method="post" action="admin_upfile.php" enctype="multipart/f……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1812浏览 0评论2558个赞
php强制下载文件的代码header("Content-type: application/octet-stream");// displays progress bar when downloading (credits to Felix ;-))header("Content-Length: " . fi……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2808浏览 0评论1214个赞
php取得字符串的首字母(适用于中文字符串)转自:http://blog.1dnet.net/?post=838<?php$limit = array( //gb2312 拼音排序 array(45217,45252), //A array(45253,45760), //B array(45761,46317), //……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2943浏览 0评论1182个赞
php去除html代码中的空白和空行的代码function DeleteHtml($str){ $str = trim($str); $str = ereg_replace("\t","",$str); ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2046浏览 0评论2807个赞
PHP判断IP并转跳到相应城市分站的代码演示转自:http://blog.1dnet.net/?post=807<?php class QQWry{ var $StartIP=0; var $EndIP=0; var $Country=''; var $L……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2135浏览 0评论2287个赞