下面的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……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3101浏览 2564个赞
这段代码使用while语句对两个变量$i和$num分别进行递减和递加<html><body><?php$i = 0;$num = 50;while( $i < 10){ $num--; $i++;}echo ("Loop stopped at i = $i and num = ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2131浏览 2187个赞
如果当前日期是星期五下面的代码返回“Have a nice weekend!”,否则返回 “Have a nice day!”<html><body><?php$d=date("D");if ($d=="Fri") echo "Have……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2388浏览 543个赞
做站点时,通常要将图片缩小成合适的尺寸,jpg图片缩小比较容易,png图片如果带了透明色的话,按照jpg的方式来缩小的话,就会造成透明色损失。那么如何处理,才能保存透明色呢?主要是利用gd库的两个方法:imagecolorallocatealpha 分配颜色 + alphaimagesavealpha 设置在保存 png 图像时保存完整的 alpha ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1370浏览 2183个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3103浏览 1614个赞
下面的php代码用于测试给定密码的强度,最高强度为100<?php /** * * @param String $string * @return float * * Returns a float between 0 and 100. The closer the number is to 100 the * th……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1841浏览 729个赞
php单件模式实现代码演示<?php/** * @link https://github.com/MaGuowei * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> */ /** * 单例模式 * Class Single……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1778浏览 1886个赞
通过下面的jQuery插件,你可以将图片放在一个数组里,然后告诉jQuery图片需要在什么地方背景轮换/*** jQuery Fading background roator** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1303浏览 2572个赞
php检测apache mod_rewrite模块是否安装/** * @title Check if Apache's mod_rewrite is installed. * * @author Pierre-Henry Soria <ph7software@gmail.com>……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2617浏览 1930个赞
下面的jQuery插件允许你通过鼠标右键点击拖动overflow的元素,这个插件可以在移动设备上运行/*** jQuery Drag and Scroll** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL licenses:……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1317浏览 2634个赞
php利用反射实现插件机制的代码<?php /** * @name PHP反射API--利用反射技术实现的插件系统架构 * @author :PHPCQ.COM */ interface Iplugin{ public static function getName(); } funct……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1847浏览 1553个赞
下面的php代码可以对电子邮件地址进行简单验证和强验证,简单验证验证邮件格式和主机是否存在,强验证会连接邮件服务器进行验证,需要比较长时间<?php /* * __construct($email) takes an email address to check * * simpleCheck() ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2501浏览 1494个赞
一个自定义的php分页类代码<?phpclass Pagination{ // Default values var $items = -1; var $limit = NULL; var $target = ""; var $page = 1; var $adjacents = 1; var $showC……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1669浏览 492个赞
PHP定时执行任务的实现ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{ //这里是你要执行的……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1347浏览 860个赞
这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,例如:1332888820 格式转换成 2012-03-28 06:53:40的形式# -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1732浏览 1873个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2716浏览 2756个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2917浏览 1344个赞
python从url中获取文件名import urllib2 file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3181浏览 2384个赞
python中带有zlib库可以用来对数据进行压缩和解压缩,针对大量数据可以节省不少的空间import zlibdata='hello world'data = zlib.compress(data)#压缩#data此时的值为:'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2475浏览 2383个赞
python将文本转换成图片输出#-*- coding:utf-8 -*- from PIL import Image,ImageFont,ImageDraw text = u'欢迎访问脚本分享网,http://www.75271.com' font = ImageFont.truetype("msyh……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2705浏览 2722个赞
python通过wxPython打开并播放wav文件''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutton.FileBrowseButton(parent, labelText, fileMas……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2555浏览 1409个赞
python3 短网址和数字的相互转换import mathimport decimal def convert_to_code(num): """ 将数字转换为代码 """ def get_num(num, out=''): ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2869浏览 469个赞
python输出当前目录下的index.html文件路径import osimport sys path = os.path.join(os.path.dirname(sys.argv[0]), 'index.html')print path……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2646浏览 1468个赞
python删除列表中的重复记录def removeListDuplicates(seq): seen = set() seen_add = seen.add return [ x for x in seq if x not in seen and not seen_add(x) ]……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2818浏览 1211个赞
下面的代码通过自定义一个继承自threading.Thread的类来实现多线程编程,调用非常简单import threading import time class timer(threading.Thread): #The timer class is derived from the class threading.Thread ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2302浏览 1979个赞
python通过urllib2发送带cookie的求情import urllib2opener = urllib2.build_opener()opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))f = opener.open(&quo……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1669浏览 1039个赞
这里实现的是针对网关的欺骗。假如说,你要攻击A机器,其IP是192.168.1.100,MAC是aa:bb:cc:dd:ee:ff,这样你就可以发给网关一个伪造包,包的源IP为192.168.1.100,源MAC为00:11:22:33:44:55,这样就实现对了网关的欺骗。转自:http://www.cnblogs.com/lovedboy/#co……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2026浏览 2872个赞
python在windows下操作word的方法import win32comfrom win32com.client import Dispatch, constantsw = win32com.client.Dispatch('Word.Application')# 或者使用下面的方法,使用启动独立的进程:# w = ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1626浏览 2989个赞
python arp欺骗伪造网关代码转自:http://www.cnblogs.com/lovedboy/#coding:utf-8'''arp欺骗局域网pc,将伪造的网关mac以网关的arp应答发送给pc'''from scapy.all import ARP,send,arpin……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2813浏览 1948个赞
python通过win32com打开word,excel,ppt,并控制其最大化、最小化显示import win32com.clientw=win32com.client.Dispatch("Word.Application")w.Visible=True #控制word显示w.WindowState = 1 #1表示正常,2……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2835浏览 2780个赞
如果一个函数中所有递归形式的调用都出现在函数的末尾,我们称这个递归函数是尾递归的。当递归调用是整个函数体中最后执行的语句且它的返回值不属于表达式的一部分时,这个递归调用就是尾递归。尾递归函数的特点是在回归过程中不用做任何操作,这个特性很重要,因为大多数现代的编译器会利用这种特点自动生成优化的代码。原理当编译器检测到一个函数调用是尾递归的时候,它就覆盖当前……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1707浏览 1310个赞
python从网络下载文件并获得文件大小、文件类型import urllib2from settings import COOKIES opener = urllib2.build_opener() cookies = ";".join("%s=%s" % (k, v) for k, v in COO……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2065浏览 1860个赞
python里用java的模块SmartXLS和jpype修改excel文件# -*- coding: utf8 -*-"""使用java的模块SmartXLS[http://www.smartxls.com/indexj.htm]和jpype修改excel和xlrd,xlwt不同的是它可以生成和保持图表"……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2772浏览 1766个赞
python Web 框架bottle超清晰使用范例,通过这个范例你可以大概了解bottle是如何使用的#coding: utf-8from bottle import route, error, post, get, run, static_file, abort, redirect, response, request, template@r……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1260浏览 335个赞
linux下通过python获得指定网卡的ip地址import socketimport fcntlimport struct def get_ip_address(ifname): """ >>> get_ip_address('lo') '1……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2867浏览 748个赞
python将pvr格式转换成pvr.cczimport zlibimport structimport syspvr = sys.argv[1]ccz = pvr + ".ccz"pvr = open(pvr).read()ccz = open(ccz, "wb")ccz.write(str……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2006浏览 2501个赞
从脚本里运行scrapy的代码# This snippet can be used to run scrapy spiders independent of scrapyd or the scrapy command line tool and use it from a script. # # The multiprocessing librar……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1766浏览 1565个赞
python通过google api抓取google搜索结果,其中q参数为要搜索的关键词#!/usr/bin/python import urllib import simplejson query = urllib.urlencode({'q' : '75271.com'}) ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2690浏览 1154个赞
python通过mmap库映射文件到内存用法详解转自:http://blog.chinaunix.net/uid-20393955-id-1645587.html         &……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2898浏览 2643个赞
python编写的两个简单的文本类游戏############################################################# - My version on the game "Dragon Realm".# - taken from the book "invent with py……继续阅读 » 水墨上仙 4年前 (2021-03-10) 3128浏览 2061个赞
python通过程序向ppt文件里面插入新的幻灯片页面# -*- coding: UTF-8 -*-import win32com.clientimport win32com.client.dynamicimport os #我的範本(Template)檔名為 BugCurve.pptxdef PowerPoint(): ppt =……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1568浏览 435个赞
python通过fileinput模块逐行读取文件#------------------------------------------------------------------------------# Name: read_lines.py# Author: Kevin Harris# Last M……继续阅读 » 水墨上仙 4年前 (2021-03-10) 1411浏览 2361个赞
python控制随机间隔一段时间发送邮件、消息或弹出窗口""" If you need to do something irregularly, randomly during the weekday, youoften forget. This script gives you mail, sms or popup w……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2851浏览 2765个赞
python scrapy 网络采集使用代理的方法 1.在Scrapy工程下新建“middlewares.py”# Importing base64 library because we'll need it ONLY in case if the proxy we ……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2907浏览 976个赞
时间限制:1000 ms | 内存限制:65535 KB输入两个整数a,b (0……继续阅读 » 水墨上仙 4年前 (2021-03-10) 2117浏览 2444个赞