51CTO自动登录,领下载豆,领无忧币#coding:UTF-8import urllib,urllib2,cookielib,re,randomclass Login: _login_url = 'http://home.51cto.com/index.php?s=/Index/doLogin' _metho……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2697浏览 1651个赞
使用PHP做Whois检查function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace('/^http:\/\//i', '……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3321浏览 229个赞
Windows下批处理通过wget获得本机上网ip地址,改代码需要安装wget命令,可以到下面的地址下载windows版本的wget: http://www.gnu.org/software/wget/wget.html@ECHO OFF:: Check Windows versionIF NOT "%OS%"=="Wi……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2750浏览 914个赞
首先下载类库包 地址:http://phpqrcode.sourceforge.net/下载:http://sourceforge.net/projects/phpqrcode/<? include "./phpqrcode/phpqrcode.php"; $value="http://www.75271.co……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2661浏览 2292个赞
有的时候需要用HASH来对数据标注,PHP下无疑就是Md5了,不过呢如果这个哈希是给用户看的呢?总之试图实现4chan的tripcode(绊码)功能时候发现:/********** CHash provides users with a fairly strong but short hash for identification* Based o……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3087浏览 585个赞
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……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3298浏览 692个赞
使用PHP进行字符串循环$string = "Your String";for($i=0;$i<strlen($string);$i++){ $char = substr($string,$i,1);} ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3494浏览 2312个赞
批量去除UTF8的Bom标签#!/usr/bin/python#coding=utf-8import osimport sysimport codecsclass RemoveBom: basePath = '' fileList = [] trimExtList = [] ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3137浏览 1584个赞
这是一个函数定位接收一个字符串作为参数(连同其他配置可选参数),并且定位该字符串中的所有关键字(出现最多的词),返回一个数组或一个字符串由逗号分隔的关键字。功能正常工作,但我正在改进,因此,有任何的建议请评论。/** * Finds all of the keywords (words that appear most) on param $str ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3042浏览 2033个赞
背包问题描述:一个承受最大重量为W的背包,现在有n个物品,每个物品重量为t, 每个物品的价值为v。 要使得这个背包重量最大(但不能超过W),同时又需要背包的价值最大。 转自:http://blog.csdn.net/oceanwavewyt/article/details/4479498<? /***背包问题描述:一个承受最大重量为W的背包,现……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2339浏览 1012个赞
根据《软件设计师》教程的伪代码写的;最麻烦的不是伪代码改成php,而是数组下标从0开始,及相应的下标判断问题;带着调试输出一块写上出处:http://blog.csdn.net/masofeng/article/details/8658368<?php $v_arr = array(11,21,31,33,43,53,55,65); $w_……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2187浏览 2015个赞
给出两个数值X和Y,统计在这个区间里的回文数,并且要求它们的平方根也是回文数。其中 1……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1937浏览 1888个赞
“回文数”是一种数字。如:98789, 这个数字正读是98789,倒读也是98789,正读倒读一样,所以这个数字就是回文数。<?php for($i=10;$i<100;$i++){ $len=strlen($i); $l=1; $k=intval($len)/2+1; ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2222浏览 415个赞
PHP判断一个字符串是否是回文字符串<?php function ishuiwen($str){ $len=strlen($str); $l=1; $k=intval($len/2)+1; for($j=0;$j<$k;$j++){ if (substr($str,$j,1)!=substr($s……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3159浏览 825个赞
php在网页上将mysql数据转换到excel输出的代码<?php$DB_Server = "localhost";$DB_Username = "mydowns";$DB_Password = "";$DB_DBName = "mydowns";$DB_TB……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3263浏览 1950个赞
php导出CSV文件代码,可供Excel读取<?php// 这里要注意包含类路径要正确require_once(dirname(__FILE__) . '/export.php');$exceler= newJason_Excel_Export(); // 生成excel格式 这里根据后缀名不同而生成不同的格式。$e……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3096浏览 2841个赞
php通过com连接excel并输出数据<?php//定义一个excel文件$workbook = "C:/My Documents/test.xls";$sheet = "Sheet1";//生成一个com对象$ex$ex = new COM("Excel.sheet") or……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2820浏览 373个赞
贪心算法解决0-1背包问题,全局最优解通过局部最优解来获得!比动态规划解决背包问题更灵活!//0-1背包贪心算法问题class tanxin{ public $weight; public $price; public function __construct($weight=0,$price=0) { $this->weight=$……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3104浏览 929个赞
php丽娜姐到mysql数据库并进行简单的查询过程演示<?php$DB_HOST = "localhost";$DB_NAME = "db";$DB_USER = "user";$DB_PASSWORD = "pass";$con = mysql_connec……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1785浏览 2444个赞
PHP连接到Mongodb的方法 下面的代码直接链接到本地mongdb服务器,端口使用默认的27017$connection = new Mongo(); 下面的代码链接到172.20.10.8的mong……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3274浏览 2476个赞
在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到最终的结果,怎么样不错吧。 其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头用header(“Co……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1646浏览 2551个赞
默认情况下scrapy采集时只能使用一种user-agent,这样容易被网站屏蔽,下面的代码可以从预先定义的user-agent的列表中随机选择一个来采集不同的页面 在settings.py中添加以下代码DOWNLOADER_MIDDLEWARES = { ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 4223浏览 1896个赞
php写入数据到CSV文件范例代码<?php$row = 0;ini_set('max_execution_time', 300);$cate;$item;$value;$us;$fp = fopen("torah1.csv", "w");if (($handle = fope……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1651浏览 248个赞
php列出当前目录下的所有php文件<?php//Define directory for files listing//original example//$files = glob('/path/to/dir/*.xml');$files = glob('*.php');//to limit ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1708浏览 2163个赞
这段代码判断当前日期是星期几,根据返回值输出Today is Monday的字样,使用switch语句记得每个case后面跟着一个break语句<html><body><?php$d=date("D");switch ($d){case "Mon": echo &qu……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1499浏览 1339个赞
很多网站,比如twitter,京东商城首页,会在页面滚动到一定的位置时才动态加载页面内容,这样可以加快页面打开的速度,也可以节约带宽,下面的JS代码就可以帮你做到。var loading = false;$(window).scroll(function(){ if((($(window).scrollTop()+$(window).height(……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2428浏览 1876个赞
php中可以通过define函数定义常量,调用的时候可以直接使用常量名称也可也使用constant函数调用,下面的例子详细演示了php中常量的使用方法。<?phpdefine("MINSIZE", 50);echo MINSIZE;echo constant("MINSIZE"); // same……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1761浏览 2314个赞
下面的php代码分别对变量$a和$b进行循环累加<html><body><?php$a = 0;$b = 0;for( $i=0; $i<5; $i++ ){ $a += 10; $b += 5;}echo ("At the end of the loop a=$a and……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3236浏览 2267个赞
这段代码使用while语句对两个变量$i和$num分别进行递减和递加<html><body><?php$i = 0;$num = 50;while( $i < 10){ $num--; $i++;}echo ("Loop stopped at i = $i and num = ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3175浏览 1845个赞
如果当前日期是星期五下面的代码返回“Have a nice weekend!”,否则返回 “Have a nice day!”<html><body><?php$d=date("D");if ($d=="Fri") echo "Have……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2527浏览 1969个赞
做站点时,通常要将图片缩小成合适的尺寸,jpg图片缩小比较容易,png图片如果带了透明色的话,按照jpg的方式来缩小的话,就会造成透明色损失。那么如何处理,才能保存透明色呢?主要是利用gd库的两个方法:imagecolorallocatealpha 分配颜色 + alphaimagesavealpha 设置在保存 png 图像时保存完整的 alpha ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2516浏览 187个赞
php从数组中随机选择若干唯一元素<?php /* * $array = the array to be filtered * $total = the maximum number of items to return * $unique = whether or not to remove duplicates before g……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2106浏览 573个赞
下面的php代码用于测试给定密码的强度,最高强度为100<?php /** * * @param String $string * @return float * * Returns a float between 0 and 100. The closer the number is to 100 the * th……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2830浏览 1399个赞
php单件模式实现代码演示<?php/** * @link https://github.com/MaGuowei * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> */ /** * 单例模式 * Class Single……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3083浏览 424个赞
通过下面的jQuery插件,你可以将图片放在一个数组里,然后告诉jQuery图片需要在什么地方背景轮换/*** jQuery Fading background roator** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2278浏览 1719个赞
php检测apache mod_rewrite模块是否安装/** * @title Check if Apache's mod_rewrite is installed. * * @author Pierre-Henry Soria <ph7software@gmail.com>……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2303浏览 1812个赞
下面的jQuery插件允许你通过鼠标右键点击拖动overflow的元素,这个插件可以在移动设备上运行/*** jQuery Drag and Scroll** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL licenses:……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2535浏览 2640个赞
php利用反射实现插件机制的代码<?php /** * @name PHP反射API--利用反射技术实现的插件系统架构 * @author :PHPCQ.COM */ interface Iplugin{ public static function getName(); } funct……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2120浏览 1903个赞
下面的php代码可以对电子邮件地址进行简单验证和强验证,简单验证验证邮件格式和主机是否存在,强验证会连接邮件服务器进行验证,需要比较长时间<?php /* * __construct($email) takes an email address to check * * simpleCheck() ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3150浏览 2623个赞
一个自定义的php分页类代码<?phpclass Pagination{ // Default values var $items = -1; var $limit = NULL; var $target = ""; var $page = 1; var $adjacents = 1; var $showC……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2820浏览 353个赞
PHP定时执行任务的实现ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{ //这里是你要执行的……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1897浏览 2215个赞
这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,例如:1332888820 格式转换成 2012-03-28 06:53:40的形式# -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1637浏览 2986个赞
This is a simple function that runs another function in a different process by forking a new process which runs the function and waiting for the result in the parent. This can be u……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3136浏览 1808个赞
Python通过win32api递归遍历目录删除指定文件import win32conimport win32apiimport osdef del_dir(self,path): for file in os.listdir(path): file_or_dir = os.path.join(path,file) if os.pat……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3247浏览 2327个赞
python从url中获取文件名import urllib2 file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3082浏览 1514个赞