php插入法排序代码演示来源:http://blog.csdn.net/zhongchengl/article/details/7948956<?php //插入排序 按从小到大排序 $insert=array(); for($i=0;$i<200;$i++) { $insert[$i]=rand(0……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3128浏览 0评论1331个赞
php检测字符串中是否包含HTML代码<?php function has_html($string){ if(strlen($string) != strlen(strip_tags($string))){ return true; } return false; } var_dump(ha……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2373浏览 0评论503个赞
php程序内部post数据的代码$postData = array();$postData['data1'] = "testdata1";$postData['data2'] = "testdata2";$postData['data3'] = &……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2068浏览 0评论557个赞
在做一个小项目的时候用得gbk,发现json_encode传过来的汉子不对。搜索出结果。。留下印子不忘记。。欢迎指正。function ArrEncode($arr){ foreach($arr as $k=>$v){ if(is_array($v)){ $arr[$k] =ArrEncode($v); }else{ $……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1880浏览 0评论2055个赞
CVS文件转换成php数组sample.csv----------------name,email政府,gov@gov.gov---------------- =======================================<?php function str_to_csv( $row ){ if( $row=……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1966浏览 0评论710个赞
C语言统计php代码的行数/** * @date 2012-12-1 * @author bright * @todo 统计php代码行数 */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1710浏览 0评论2989个赞
最近有项目需要将txt文档通过openoffice转为PDF,然后在通过swftools将PDF转为swf,在linux系统下的字符编码方式为utf-8,所以需将不是UTF-8的文本文档转换为UTF-8function chkCode($string){ $code = array('UTF-8','GBK',……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3326浏览 0评论2331个赞
PHP 以 Post 方式请求网页数据/** * Post 方式请求网页数据 * * @param string $url 网页地址 * @prarm string $host 主机 * @param string $session 会话值 * @prarm string $type 类型(POS……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2472浏览 0评论2533个赞
php获得中文字符串的长度,一个中文算2个字符$str = 'Hello,世界!';preg_match_all('/./us', $str, $match);echo count($match[0]); // 输出9……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2074浏览 0评论2164个赞
php生成随机密码/** * Order by phpno.com * @param num 密码的随机最小长度 * @param num 密码的随机最大长度 * @param bool 是否使用特殊字符 */function random_passwd($min_len=8,$max_len=16,$special=FALSE){ $p……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2740浏览 0评论2423个赞
自己写了个计算页面执行时间的脚本 执行时间会显示在页面右上角优点是只要在开始的时候执行一下就可以了<?php$t = new executeTime;phpinfo();class executeTime{ private $microtime; public function __construct(){ $this->mi……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1796浏览 0评论2509个赞
根据浏览器Agent识别用户的操作系统,从而确定用户设备是手机还是PC$uAgent = $_SERVER['HTTP_USER_AGENT'];$osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Wi……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1312浏览 0评论1352个赞
php阿拉伯数字转化为中文汉字(大、小写)function number2Chinese($num, $m = 1) { switch($m) { case 0: $CNum = array( array('零','壹','贰','叁','……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1979浏览 0评论2632个赞
PHP遍历指定目录下的文件<?php $num=0; //用来记录目录下的文件个数 $dirname='LAMP'; //要遍历的目录名字 $dir_handle=opendir($dirname); echo '<table border="1" align……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2245浏览 0评论1719个赞
json格式post到wordpress<?php// include our wordpress functions// change relative path to find your WP dirdefine('WP_USE_THEMES', false);require('./wp-blog-hea……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2010浏览 0评论1690个赞
php请求github api的客户端代码<?php// http client making a request to github apirequire __DIR__.'/../vendor/autoload.php';$loop = React\EventLoop\Factory::create();$clie……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2188浏览 0评论1213个赞
php冒泡法排序代码function bubbleSort ($items) { $size = count($items); for ($i=0; $i<$size; $i++) { for ($j=0; $j<$size-1-$i; $j++) { if ($……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1999浏览 0评论2113个赞
jQuery取消ajax请求的代码,要注意的是,在ajax请求未响应之前可以用xhr.abort()取消,但如果请求已经到达了服务器端,这样做的结果仅仅是让浏览器不再监听这个请求的响应,但服务器端仍然会进行处理var xhr = $.ajax({ type: "POST", url: "test.php&q……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1464浏览 0评论1330个赞
php删除目录代码片段 <?php if (file_exists("./dummydir")) { if(is_dir("./dummydir")) { $result = rmdir("./dummydir"); echo "Resu……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2797浏览 0评论1467个赞
php连接mysql数据库简单范例<?php/*create table user1(id int primary key auto_increment,name varchar(32) not null,password varchar(64) not null,email varchar(32) not null,age tin……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2940浏览 0评论933个赞
php添加字符串到文件的代码$fp = fopen("filename", "a"); if($fp) { fwrite($fp, "aString"); fclose($fp); } ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 4078浏览 0评论1302个赞
php高并发下写文件function write($data) { $return = false; if ($handle = @fopen('error.txt','a+') ) { $i=0; while (!flock($handle,2) &&am……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2674浏览 0评论848个赞
php编写的简单随机抽奖函数<?php/** * “抽奖”函数 * * @param integer $first 起始编号 * @param integer $last 结束编号 * @param integer $total 获奖人数 * * @return string **/function isWinner($f……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1661浏览 0评论2419个赞
php获取文件大小的代码$file_size = filesize('filename'); ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3416浏览 0评论1210个赞
这个有用的函数能将秒数表示的事件转换为年、月、日、小时等时间格式。function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1346浏览 0评论1064个赞
php正则表达式检查邮件地址是否正确function checkEmail($email) { // Create the syntactical validation regular expression $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1296浏览 0评论1536个赞
php中使用base HTTP验证function http_auth($un, $pw, $realm = "Secured Area"){ if(!(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2503浏览 0评论843个赞
完全面向对象的php操作mssql类<?php/*untested*/class database_mssql {var $database = NULL;var $sqls = NULL;var $host = NULL;var $username = NULL;var $password = NULL;var $datab……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3245浏览 0评论1534个赞
通过错误显示开关和错误级别显示php错误信息ini_set('display_errors', "1");ini_set('error_reporting', E_ALL ^ E_NOTICE);……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2925浏览 0评论1864个赞
一个php类,封装了php操作mysql的基本方法,包含数据库链接,基本的数据查询方法<?PHP class Database { var $db; var $result; var $lastQuery; var $numQueries = 0; var $error; var $showErrors = true;……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1876浏览 0评论2577个赞
这段代码允许你通过php内置方法下载其它网站上的文件,无需安装任何扩展if (!function_exists('fetch_remote_file')) { function fetch_remote_file($file) { $path = parse_url($file); $fs ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1432浏览 0评论1138个赞
phpinfo 函数如学习php不可不知的函数,他能显示服务器端的一系列信息,代码就一句<?php phpinfo();?>……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3691浏览 0评论1957个赞
根据给定的url,抓取url的内容,可以设置抓取超时function geturl($url){ $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_se……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2376浏览 0评论2461个赞
php生成的美国50个州的选择列表,自动选择当前州<select name="state" id="state"> <option value="AL" <?PHP if($state=="AL") echo "selected"……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1488浏览 0评论2502个赞
php封装的用户登陆验证的类,实现了用户登陆的常用功能,包含cookie和session的设置class Auth{ var $user_id; var $username; var $password; var $ok; var $salt = "34asdf34"; var $domain = ".dom……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2242浏览 0评论461个赞
php 数据库操作基础类DBObject Class/* WORKS IN PHP5 ONLY */ class DBObject { private $id; private $id_field; private $table_name; private $fields = array(); function __co……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1680浏览 0评论687个赞
这个是一个php对session的再次包装的类,实现的常用的session操作,包含读取,写入,销毁等等class Session{ function Session() { session_start(); } function set($name, $value) { $_SESSION[$name] = $value; ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2627浏览 0评论1003个赞
修改form的target为iframe的id即可<form action="iframe.php" target="my-iframe" method="post"><input type="text" name="text" id……继续阅读 » 水墨上仙 5年前 (2021-01-15) 4184浏览 0评论2721个赞
php查询数据库并分页,输出分页的html代码$db->query("SELECT COUNT(*) FROM snippets s WHERE s.user_id = '$user_id'"); $numRecords = mysql_result($db->result, 0, 0); $nu……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1430浏览 0评论1694个赞
通过修改header的location实现转向function redirect($url){ header("Location: $url"); exit();}……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3875浏览 0评论1626个赞
一个专门用来生成RSS的php类/* E X A M P L E ----------------------------------------------- $feed = new RSS(); $feed->title = "RSS Feed Title"; $feed->link ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1664浏览 0评论2515个赞
将unix时间戳输出为类似于 20秒前,1天前,3个月前这样的格式<?phpfunction user_friendly_date($timestamp, $echo = false, $dateFormat = 'm/d/Y H:i:s'){ $ufdate = ''; $now = time()……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2797浏览 0评论2536个赞
如果你想把rgb颜色编程hex颜色编码就用这个函数function rgb2hex($rgb){ return sprintf("%06X", $rgb);}//使用范例:print rgb2hex(0x00FF00);// returns --> 00FF00 print rgb2hex(65280);/……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1632浏览 0评论781个赞
这段php代码可以把一个颜色变成与之相反的颜色编码,如:白色变成黑色,蓝色变成黄色function color_inverse($color){ $color = str_replace('#', '', $color); if (strlen($color) != 6){ return ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3076浏览 0评论204个赞
这段代码可以帮助你检测用户的终端设备室平板电脑,手机还是桌面电脑,分别返回”tablet”,”mobile”,”desktop”<?php function userAgent($ua){ ## This credit must stay intact (Unless y……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1659浏览 0评论2291个赞