php可以通过rmdir()函数删除服务器上的目录,下面代码里用到了is_dir()函数,该函数用于判断指定的字符串是否是目录,删除成功返回True,否则返回False<?phpif (!is_dir('exampledir')) { mkdir('exampledir');} rmdir(&……继续阅读 » 6年前 (2021-03-10) 3088浏览 1872个赞
php中可以通过usleep()函数让脚本暂停顺序执行一段时间,参数单位为毫秒<? usleep(4000000); echo "Done\n";?>……继续阅读 » 6年前 (2021-03-10) 3232浏览 477个赞
php中可以通过set_time_limit()函数限制脚本的最长执行时间,单位为秒<? set_time_limit(30); //要执行的代码?> 上面的代码控制脚本最长只能执行30秒,30秒后将抛出异常……继续阅读 » 6年前 (2021-03-10) 3744浏览 1805个赞
php使用递归函数实现数字累加,下面是一个简单的范例<?function summation ($count) { if ($count != 0) : return $count + summation($count-1); endif;}$sum = summation(10);print &qu……继续阅读 » 6年前 (2021-03-10) 2654浏览 2784个赞
sort()函数用于给数组排序,本函数为数组中的单元赋予新的键名。原有的键名将被删除。如果成功则返回 TRUE,否则返回 FALSE。$alpha = array ("x", "a", "f", "c");sort( $alpha ); foreach ( $alph……继续阅读 » 6年前 (2021-03-10) 3299浏览 2859个赞
linux下php可以通过mkdir创建目录,并制定目录访问权限mkdir( "testdir", 0777 ); // global read/write/execute permissionsmkdir( "testdir", 0755 ); // world and group: read/execute ……继续阅读 » 6年前 (2021-03-10) 3157浏览 360个赞
wordwrap()函数可以按照指定的固定行长度格式化文本段落,让段落看起来更加整齐<?php$string = "TRADING ON MARGIN POSES ADDITIONAL RISKS AND IS NOT SUITABLE FOR ALL INVESTORS. A COMPLETE LIST OF T……继续阅读 » 6年前 (2021-03-10) 3303浏览 967个赞
php通过strlen()函数计算字符串的长度<?php print(strlen('It\'s monday!'));?> 上面的代码输出结果:12……继续阅读 » 6年前 (2021-03-10) 2350浏览 1434个赞
php codeigniter中一次性加载多个view的方法function somecontrollerfunction(){$data['pagetitle'] = "Welcome to w3mentor.com";$this->load->view('pageheader……继续阅读 » 6年前 (2021-03-10) 1789浏览 1749个赞
php给每个段落添加空格的代码<?php //Prepends whitespace to each line of a string function white_space( $string, $whitespace ) { //Create an array from the string, each key having……继续阅读 » 6年前 (2021-03-10) 2900浏览 910个赞
php链接mysql并保存email和username的范例代码<?php //opens connnection to mysql server $dbc = mysql_connect('localhost','root','');if (!dbc){ die(……继续阅读 » 6年前 (2021-03-10) 2891浏览 1575个赞
headers_list函数没有参数,并返回一个数组。返回的数组包含一个数字索引表,包含了要发送给客户端的header信息<?php header("Expires: Sat, 12 Dec 1989 05:30:00 GMT"); echo "This is some output.&……继续阅读 » 6年前 (2021-03-10) 2993浏览 2775个赞
php使用mysqli向数据库添加数据$mydb = new mysqli('localhost', 'username', 'password', 'databasename');$sql = "INSERT INTO users (fname, lname, ……继续阅读 » 6年前 (2021-03-10) 2480浏览 1951个赞
php通过mysqli接口检索和显示数据的代码$mydb = new mysqli('localhost', 'username', 'password', 'databasename');$sql = "SELECT * FROM users ORDER BY ……继续阅读 » 6年前 (2021-03-10) 2949浏览 2080个赞
php codeigniter views中通过循环显示数组数据 controller如下:<?phpclass SimpleController extends Controller{function index() { $data['my_lis……继续阅读 » 6年前 (2021-03-10) 2049浏览 1234个赞
php显示指定目录的子目录方法<?phpecho "<h2>subdirs in dir</h2><ul>";$basedir = basename( __FILE__ );$dirtoscan = ($basedir . '/somedir/');$albumli……继续阅读 » 6年前 (2021-03-10) 2434浏览 2836个赞
双向循环队列-php实现历史记录的前进后退等功能<?php include 'debug.php';/*** 历史记录操作类* 传入或者构造一个数组。形如:array( 'history_num'=>20, //队列节点总共个数 'first'=>0, ……继续阅读 » 6年前 (2021-03-10) 1939浏览 548个赞
session 数据库交互类<?php/** * session 数据库存储类 */class Session { private static $session_id = 0; private static $session_data = array(); private static $is_update = F……继续阅读 » 6年前 (2021-03-10) 2198浏览 157个赞
删除指定字符串之后或之前所有字符的函数<?php/*函数一 作用 排除 l代表排除指定字符串左边的,r代表排除指定字符串右边的*/function paichu($mub,$zhi,$a){ if(!$mub){ return "被替换的字符串不存在"; } $mub = mb_convert_encodi……继续阅读 » 6年前 (2021-03-10) 2728浏览 1337个赞
php可以逆转的加密类<?class encryptCalss{var $key=12;function encode($txt){for($i=0;$i<strlen($txt);$i++){$txt[$i]=chr(ord($txt[$i])+$this->key);}return $txt=urlencode(b……继续阅读 » 6年前 (2021-03-10) 2859浏览 2408个赞
PHP远程图片保存到本地<?php function get_file($url,$folder,$pic_name){ set_time_limit(24*60*60); //限制最大的执行时间 $destination_folder=$folder?$folder.'/':''; //文件下……继续阅读 » 6年前 (2021-03-10) 3061浏览 2795个赞
PHP获取当前网址function current_urli() { $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'ht……继续阅读 » 6年前 (2021-03-10) 2801浏览 2362个赞
php上传多个文件<?php/* Form */echo '<b>-------- UPLOADING --------</b>';echo "\r\n" . '<form action="" method="POST" e……继续阅读 » 6年前 (2021-03-10) 2094浏览 1566个赞
PHP监控服务器【LNMPA】<?php$url=array();$url[]='http://hk.qeejoo.com';$url[]='http://sz.qeejoo.com';$url[]='http://gz.qeejoo.com';$url[]='http……继续阅读 » 6年前 (2021-03-10) 2398浏览 1467个赞
php实现简单的日历类<?phpclass calendar{ private $year; private $month; private $day_week; function __construct(){ $this->year=isset($_GET['year']) ? $_GET['……继续阅读 » 6年前 (2021-03-10) 1821浏览 2068个赞
长文章分页显示类<?php/** * 文章分页类 * * @author ymz lymz.86@gmail.com * @version 1.3 *//*For example:$curPage = $_GET['page'];$totalPage = $curPage;$objArt = new ……继续阅读 » 6年前 (2021-03-10) 2989浏览 2436个赞
通过淘宝IP地址库获取IP位置1. 请求接口(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]2. 响应信息:(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商3. 返回数据格式:{"code":0,"data":{……继续阅读 » 6年前 (2021-03-10) 1416浏览 199个赞
通过Email发送PHP错误<?php// Our custom error handlerfunction nettuts_error_handler($number, $message, $file, $line, $vars){ $email = " <p>An error ($number) occurr……继续阅读 » 6年前 (2021-03-10) 1568浏览 718个赞
php解决 约瑟夫问题问题描述:有n人围成一圈,从任意一个人开始,依次报数,数到m时,第m个人出界(即出圈),出界的下一个人继续从1开始报数 ,数到m时,第m个同样出界,依次类推<?phpheader("content-type:text/html;charset=utf-8");set_time_limit(0);/**……继续阅读 » 6年前 (2021-03-10) 2244浏览 803个赞
一群猴子排成一圈,按1,2,…,n依次编号。然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数, 再数到第m只,在把它踢出去…,如此不停的进行下去, 直到最后只剩下一只猴子为止,那只猴子就叫做大王。要求编程模拟此过程,输入m、n, 输出最后那个大王的编号。[解析] 约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2……继续阅读 » 6年前 (2021-03-10) 2207浏览 393个赞
使用 PHP 和 Google 获取域名的 favicon 图标function get_favicon($url){ $url = str_replace("http://",'',$url); return "http://www.google.com/s2/favicons?domain=……继续阅读 » 6年前 (2021-03-10) 2126浏览 2033个赞
古代某法官要判决IV个犯人的死刑,他有一条荒唐的法律将犯人站成一个圆圈,从第s个人开始数起,每到第D个人就拉出来处死,然后再数D个,再拉出来处决…… 直到剩下最后一个可以赦免.function getNum($n,$m){ //用于把所有的数存到数组初始化 $a = array(); //遍历,存入数组 for($i=1;……继续阅读 » 6年前 (2021-03-10) 1868浏览 251个赞
51CTO自动登录,领下载豆,领无忧币#coding:UTF-8import urllib,urllib2,cookielib,re,randomclass Login: _login_url = 'http://home.51cto.com/index.php?s=/Index/doLogin' _metho……继续阅读 » 6年前 (2021-03-10) 1773浏览 208个赞
Windows下批处理通过wget获得本机上网ip地址,改代码需要安装wget命令,可以到下面的地址下载windows版本的wget: http://www.gnu.org/software/wget/wget.html@ECHO OFF:: Check Windows versionIF NOT "%OS%"=="Wi……继续阅读 » 6年前 (2021-03-10) 2271浏览 2962个赞
使用PHP做Whois检查function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace('/^http:\/\//i', '……继续阅读 » 6年前 (2021-03-10) 2122浏览 815个赞
首先下载类库包 地址:http://phpqrcode.sourceforge.net/下载:http://sourceforge.net/projects/phpqrcode/<? include "./phpqrcode/phpqrcode.php"; $value="http://www.75271.co……继续阅读 » 6年前 (2021-03-10) 2925浏览 756个赞
有的时候需要用HASH来对数据标注,PHP下无疑就是Md5了,不过呢如果这个哈希是给用户看的呢?总之试图实现4chan的tripcode(绊码)功能时候发现:/********** CHash provides users with a fairly strong but short hash for identification* Based o……继续阅读 » 6年前 (2021-03-10) 2567浏览 1652个赞
python读取目录下文件并生成日志import os from time import strftime stamp=strftime("%Y-%m-%d %H:%M:%S") logfile = 'F://test//m-php-framework//tmp/logs//error_report.log……继续阅读 » 6年前 (2021-03-10) 2658浏览 1942个赞
使用PHP进行字符串循环$string = "Your String";for($i=0;$i<strlen($string);$i++){ $char = substr($string,$i,1);} ……继续阅读 » 6年前 (2021-03-10) 2663浏览 900个赞
这是一个函数定位接收一个字符串作为参数(连同其他配置可选参数),并且定位该字符串中的所有关键字(出现最多的词),返回一个数组或一个字符串由逗号分隔的关键字。功能正常工作,但我正在改进,因此,有任何的建议请评论。/** * Finds all of the keywords (words that appear most) on param $str ……继续阅读 » 6年前 (2021-03-10) 1934浏览 170个赞
批量去除UTF8的Bom标签#!/usr/bin/python#coding=utf-8import osimport sysimport codecsclass RemoveBom: basePath = '' fileList = [] trimExtList = [] ……继续阅读 » 6年前 (2021-03-10) 2526浏览 1648个赞
背包问题描述:一个承受最大重量为W的背包,现在有n个物品,每个物品重量为t, 每个物品的价值为v。 要使得这个背包重量最大(但不能超过W),同时又需要背包的价值最大。 转自:http://blog.csdn.net/oceanwavewyt/article/details/4479498<? /***背包问题描述:一个承受最大重量为W的背包,现……继续阅读 » 6年前 (2021-03-10) 2016浏览 1963个赞
根据《软件设计师》教程的伪代码写的;最麻烦的不是伪代码改成php,而是数组下标从0开始,及相应的下标判断问题;带着调试输出一块写上出处:http://blog.csdn.net/masofeng/article/details/8658368<?php $v_arr = array(11,21,31,33,43,53,55,65); $w_……继续阅读 » 6年前 (2021-03-10) 2871浏览 1938个赞
给出两个数值X和Y,统计在这个区间里的回文数,并且要求它们的平方根也是回文数。其中 1……继续阅读 » 6年前 (2021-03-10) 2234浏览 2257个赞
“回文数”是一种数字。如:98789, 这个数字正读是98789,倒读也是98789,正读倒读一样,所以这个数字就是回文数。<?php for($i=10;$i<100;$i++){ $len=strlen($i); $l=1; $k=intval($len)/2+1; ……继续阅读 » 6年前 (2021-03-10) 1684浏览 1601个赞