PHP递归实现复制整个文件夹的类<?php/* * 文件夹复制类, * 赵春 2012年6月14日17:20:30 * 博客:www.zhaochun.net */class CopyFile{public $fromFile;public $toFile;/* * $fromFile 要复制谁 * $toFile ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1254浏览 1750个赞
php浏览历史记录/** * 商品历史浏览记录 * $data 商品记录信息 */private function _history($data){ if(!$data || !is_array($data)) { return false; } //判断cookie类里面是否有浏览记录 if($this->_r……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1374浏览 2057个赞
下面php代码通过gzcompress和gzuncompress压缩和解压缩字符串,可以设定压缩级别$str = 'Hello I am a very very very very long string';$compressed = gzcompress($str, 9);//压缩级别为9$uncompressed = gzu……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2007浏览 2796个赞
这段代码演示了php数组的强大功能,关联数组的创建和使用,php中的关联数组和python中的字典非常类似<html><body><?php/* First method to associate create array. */$salaries = array( "mohammad&quo……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2443浏览 2055个赞
php短网址和数字之间的相互转换代码<?php/** * 将数字转为短网址代码 * * @param int $number 数字 * @return string 短网址代码 */function generate_code($number) { $out = ""; $codes = &……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2069浏览 2340个赞
php将linux运行时间转换成更好看的格式<?php $exec = shell_exec('uptime'); $uptime = explode(' up ', $exec); $uptime = explode(',', $uptime[1]); ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2463浏览 1738个赞
将一个字符串每隔三个字符添加一个逗号,例如把字符串1234567890转换为1,234,567,890,这种做法在金融领域非常常见<?php/** * 每隔3个字符,用逗号进行分隔 * @param string $str * @return string */function splitStrWithComma ($str){……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2076浏览 992个赞
php读取csc文件并输出<?php$row = 0;$j = 1; // Linea por la que quieres empezar$file = "name.txt"; //Nombre del ficheroif (($handle = fopen($file, "r")) !== FA……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2879浏览 236个赞
php常用正则<?phpclass Verify{ /** * 验证用户名 * @param string $value * @param int $length * @return boolean */ public static function isNames($value, $minLen=2, $maxLen=20, $c……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2531浏览 1000个赞
requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的:python的标准库urllib2提供了大部分需要的HTTP功能,但是API太逆天了,一个简单的功能就需要一大堆代码。我也看了下requests的文档,确实很简单,适合我这种懒人。下面就是一……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1494浏览 264个赞
代码转自:http://www.pjblog.net/index.php?post/2004/10/12/46-imagemagickobject-et-delphiprocedure TFormMain.Convert( ImgSource, ImgDest:TImage; SizeX, SizeY : Integer;PixelFormat: TP……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2833浏览 2367个赞
利用php_apd扩展很轻松地就这把这搞定了。只有四句代码。<?phprename_function('gzuncompress','new_gzuncompress');override_function('gzuncompress', '$arg', ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2010浏览 471个赞
通过PHP得到php,mysql,apche等版本信息的代码当然你的php必须运行在apache下才能检测apache的版本号 获取当前运行的PHP的版本 <?php echo "PHP软件版本:".phpversion(); ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1209浏览 905个赞
这段代码演示了php如何通过自定义的模板页面和自定义标签生成静态页面。原理非常简单,就是将模板页面中的标签替换成动态数据即可。希望能给你一定的启发。 template.html 模板文件<!DOCTYPE html PUBLIC "-//W3C……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1420浏览 2531个赞
php函数可以使用引用类型的参数,类似于C语言里的指针<html><head><title>Passing Argument by Reference</title></head><body><?phpfunction addFive($num){ $nu……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1892浏览 162个赞
这段php代码通过fopen以写入模式打开文件,然后向其中写入文本字符串,最后关闭文件,代码简单实用<?php$filename = "/home/user/guest/newfile.txt";$file = fopen( $filename, "w" );if( $file == false )……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2396浏览 393个赞
php的函数可以设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替<html><head><title>Writing PHP Function which returns value</title></head><body><?phpfun……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1289浏览 1767个赞
这段php代码详细演示了如何打开文件、读取文件和关闭文件,php中可以通过fopen打开文件,通过filesize函数获取文件大小,fread读取文件内容,fclose关闭文件<html><head><title>Reading a file using PHP</title></head&g……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2379浏览 1174个赞
php开启多进程的代码<?php $IP='192.168.1.1';//Windows電腦的IP $Port='5900'; //VNC使用的Port $ServerPort='9999';//Linux Server對外使用的Port $RemoteSocke……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2893浏览 2214个赞
php生成多不不重复的随机数<?php/** array unique_rand( int $min, int $max, int $num )* 生成一定数量的不重复随机数* $min 和 $max: 指定随机数的范围* $num: 指定生成数量*/function unique_rand($min, $max, $num) {……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1826浏览 1242个赞
php中可以把函数名通过字符串的方式传递给一个变量,然后通过此变量动态调用函数下面是一个简单的动态函数调用范例<html><head><title>Dynamic Function Calls</title></head><body><?phpfunction ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2548浏览 221个赞
php将ip地址转换成整数比其它语言都要方便,php自带了ip2long和long2ip两个函数,方法太简单了。<?php$ip = gethostbyname('www.75271.com');$out = "The following URLs are equivalent:<br />\n&qu……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2821浏览 1179个赞
xapian按照数字范围进行检索的php范例代码,对通过add_value方法添加的属性进行范围搜索。<?phpif (php_sapi_name() != "cli") { print "This example script is written to run under the command lin……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2824浏览 2784个赞
ruby中的Dir对象可以对文件目录进行各种操作,这段代码演示了在linux和windows系统下如何列出指定目录下的文件和目录 在linux下列出根目录的结构Dir.entries("/")=> [".", "..&q……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2876浏览 2636个赞
php获取图片的exif信息,php自带一个exif_read_data函数可以用来读取图片的exif信息,代码来自php手册<?phpecho "test1.jpg:<br />\n";$exif = exif_read_data('tests/test1.jpg', 'IFD0……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2852浏览 649个赞
php按照指定长度截取字符串的代码,如果字符串超出了指定的长度,会用…替换,不过这段代码不支持中英文的区分<?php //if a string is longer than the defined length, //it will add 3 periods to the end of the string. //you ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3132浏览 2928个赞
php将指定的url网址保存为快捷方式的代码<?php$Shortcut = "[InternetShortcut]URL=http://www.75271.com/IDList=[{000214A0-0000-0000-C000-000000000046}]Prop3=19,2";Header("Cont……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1400浏览 2351个赞
Android下通过HttpClient执行 HTTP POST 请求 public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost ht……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3037浏览 938个赞
这段php代码定义了一个两个数相加的函数,调用后输出函数运行结果。<html><head><title>Writing PHP Function with Parameters</title></head><body><?phpfunction addFunct……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2650浏览 2102个赞
这里自定义了一个函数用于将zip文件解压缩,可以指定解压缩的路径<?php function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2486浏览 2743个赞
我们可以通过HTTP_USER_AGENT来判断是否是蜘蛛,搜索引擎的蜘蛛都有自己的独特标志,下面列取了一部分。function is_crawler() { $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); $spiders = array( ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2266浏览 1040个赞
php通过POST方式提交表单信息代码范例,php中通过$_POST变量获得表单post上来的信息,$_PHP_SELF表示当前页面<?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $_POST……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2948浏览 1922个赞
php 四舍五入的三种方法,分别通过number_format函数、round函数和sprintf格式化输出的方法实现四舍五入 1.number_format 方法实现四舍五入$number = 1234.5678; $nombre_format_fran……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3003浏览 1413个赞
PHP中 $_REQUEST变量包含了$_GET、$_POST和$_COOKIE三个变量的所有值无论用户通GET还是POST方式提交表单,我们都可以通过$_REQUEST变量获取表单值下面的php代码详细演示了$_REQUEST变量的用法<?php if( $_REQUEST["name"] || $_REQUEST[……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2263浏览 1465个赞
这段php代码使用while语句循环对变量$i进行累加,当$i=3时退出循环<html><body><?php$i = 0;while( $i < 10){ $i++; if( $i == 3 )break;}echo ("Loop stopped at i = $i"……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3171浏览 2090个赞
这段php代码通过foreach语句遍历数组,当遍历到数组元素值等于3时跳过循环体后面的语句,继续执行下一次循环<html><body><?php$array = array( 1, 2, 3, 4, 5);foreach( $array as $value ){ if( $value == 3 )conti……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2085浏览 2529个赞
php中可以通过$_PHP_SELF变量表示当前页面,下面的代码通过将表单的action设置为$_PHP_SELF变量将表单信息提交到当前页面<?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2003浏览 2473个赞
这段php代码定义了一个二维数组用于存储学生的学科成绩,代码演示了如何定义和使用二维数组<html><body><?php $marks = array( "mohammad" => array ( "physics" => 35, ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2750浏览 225个赞
php通过GET方式提交表单演示,$_PHP_SELF表示当前页面,php中通过$_GET变量获得用户提交的信息<?php if( $_GET["name"] || $_GET["age"] ) { echo "Welcome ". $_GET['name&……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3093浏览 2352个赞
php返回当前日期或者指定日期是星期几 PHP星期几获取代码:date("l"); //data就可以获取英文的星期比如Sundaydate("w"); //这个可以获取数字星期比如123,注意0是星期日 ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1696浏览 873个赞
php检测客户端浏览器类型代码<html><body><?php $viewer = getenv( "HTTP_USER_AGENT" ); $browser = "An unidentified browser"; if( preg_match( "……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1466浏览 1122个赞
php提交表单后页面重定向代码,这段代码提交表单到当前页面,提交后通过设置header进行页面重定向,exit()函数可以让代码强行退出不执行后面的代码<?php if( $_POST["location"] ) { $location = $_POST["location"]; ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1986浏览 2792个赞
这段php代码通过两种不同的方式创建php数组,并通过foreach语句分别遍历两个数组输出<html><body><?php/* First method to create array. */$numbers = array( 1, 2, 3, 4, 5);foreach( $numbers as $valu……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1976浏览 1544个赞
php通过rand()函数产生随机数,这个函数可以产生一个指定范围的数字这段代码通过产生的随机数,随机选择图片<html><body><?php srand( microtime() * 1000000 ); $num = rand( 1, 4 ); switch( $num ) { c……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2084浏览 657个赞
这段php代码通过do while语句对变量$i进行累加<html><body><?php$i = 0;$num = 0;do{ $i++;}while( $i < 10 );echo ("Loop stopped at i = $i" );?></body&g……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3095浏览 2322个赞