给出两个数值X和Y,统计在这个区间里的回文数,并且要求它们的平方根也是回文数。其中 1……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1931浏览 432个赞
“回文数”是一种数字。如:98789, 这个数字正读是98789,倒读也是98789,正读倒读一样,所以这个数字就是回文数。<?php for($i=10;$i<100;$i++){ $len=strlen($i); $l=1; $k=intval($len)/2+1; ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2219浏览 269个赞
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) 2736浏览 2993个赞
php在网页上将mysql数据转换到excel输出的代码<?php$DB_Server = "localhost";$DB_Username = "mydowns";$DB_Password = "";$DB_DBName = "mydowns";$DB_TB……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1939浏览 2274个赞
php导出CSV文件代码,可供Excel读取<?php// 这里要注意包含类路径要正确require_once(dirname(__FILE__) . '/export.php');$exceler= newJason_Excel_Export(); // 生成excel格式 这里根据后缀名不同而生成不同的格式。$e……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1746浏览 775个赞
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) 2840浏览 1247个赞
贪心算法解决0-1背包问题,全局最优解通过局部最优解来获得!比动态规划解决背包问题更灵活!//0-1背包贪心算法问题class tanxin{ public $weight; public $price; public function __construct($weight=0,$price=0) { $this->weight=$……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3169浏览 2069个赞
php丽娜姐到mysql数据库并进行简单的查询过程演示<?php$DB_HOST = "localhost";$DB_NAME = "db";$DB_USER = "user";$DB_PASSWORD = "pass";$con = mysql_connec……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1980浏览 278个赞
PHP连接到Mongodb的方法 下面的代码直接链接到本地mongdb服务器,端口使用默认的27017$connection = new Mongo(); 下面的代码链接到172.20.10.8的mong……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1956浏览 2915个赞
在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到最终的结果,怎么样不错吧。 其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头用header(“Co……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1488浏览 2036个赞
默认情况下scrapy采集时只能使用一种user-agent,这样容易被网站屏蔽,下面的代码可以从预先定义的user-agent的列表中随机选择一个来采集不同的页面 在settings.py中添加以下代码DOWNLOADER_MIDDLEWARES = { ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 4738浏览 1701个赞
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) 2263浏览 2939个赞
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) 2539浏览 1521个赞
这段代码判断当前日期是星期几,根据返回值输出Today is Monday的字样,使用switch语句记得每个case后面跟着一个break语句<html><body><?php$d=date("D");switch ($d){case "Mon": echo &qu……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1488浏览 2399个赞
很多网站,比如twitter,京东商城首页,会在页面滚动到一定的位置时才动态加载页面内容,这样可以加快页面打开的速度,也可以节约带宽,下面的JS代码就可以帮你做到。var loading = false;$(window).scroll(function(){ if((($(window).scrollTop()+$(window).height(……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3034浏览 1851个赞
php中可以通过define函数定义常量,调用的时候可以直接使用常量名称也可也使用constant函数调用,下面的例子详细演示了php中常量的使用方法。<?phpdefine("MINSIZE", 50);echo MINSIZE;echo constant("MINSIZE"); // same……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2066浏览 981个赞
下面的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) 1339浏览 2910个赞
这段代码使用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) 2659浏览 2834个赞
如果当前日期是星期五下面的代码返回“Have a nice weekend!”,否则返回 “Have a nice day!”<html><body><?php$d=date("D");if ($d=="Fri") echo "Have……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3275浏览 1207个赞
做站点时,通常要将图片缩小成合适的尺寸,jpg图片缩小比较容易,png图片如果带了透明色的话,按照jpg的方式来缩小的话,就会造成透明色损失。那么如何处理,才能保存透明色呢?主要是利用gd库的两个方法:imagecolorallocatealpha 分配颜色 + alphaimagesavealpha 设置在保存 png 图像时保存完整的 alpha ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2361浏览 1854个赞
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) 1402浏览 1130个赞
下面的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) 1353浏览 987个赞
php单件模式实现代码演示<?php/** * @link https://github.com/MaGuowei * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> */ /** * 单例模式 * Class Single……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2822浏览 2242个赞
通过下面的jQuery插件,你可以将图片放在一个数组里,然后告诉jQuery图片需要在什么地方背景轮换/*** jQuery Fading background roator** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1742浏览 1103个赞
php检测apache mod_rewrite模块是否安装/** * @title Check if Apache's mod_rewrite is installed. * * @author Pierre-Henry Soria <ph7software@gmail.com>……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2094浏览 1967个赞
下面的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) 2673浏览 1636个赞
php利用反射实现插件机制的代码<?php /** * @name PHP反射API--利用反射技术实现的插件系统架构 * @author :PHPCQ.COM */ interface Iplugin{ public static function getName(); } funct……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2467浏览 2318个赞
下面的php代码可以对电子邮件地址进行简单验证和强验证,简单验证验证邮件格式和主机是否存在,强验证会连接邮件服务器进行验证,需要比较长时间<?php /* * __construct($email) takes an email address to check * * simpleCheck() ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2787浏览 630个赞
一个自定义的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) 2334浏览 430个赞
PHP定时执行任务的实现ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{ //这里是你要执行的……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2729浏览 667个赞
这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,例如:1332888820 格式转换成 2012-03-28 06:53:40的形式# -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1484浏览 2197个赞
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) 1376浏览 2423个赞
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) 1682浏览 2154个赞
python从url中获取文件名import urllib2 file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3270浏览 2919个赞
python中带有zlib库可以用来对数据进行压缩和解压缩,针对大量数据可以节省不少的空间import zlibdata='hello world'data = zlib.compress(data)#压缩#data此时的值为:'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2815浏览 1964个赞
python将文本转换成图片输出#-*- coding:utf-8 -*- from PIL import Image,ImageFont,ImageDraw text = u'欢迎访问脚本分享网,http://www.75271.com' font = ImageFont.truetype("msyh……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1926浏览 2165个赞
python通过wxPython打开并播放wav文件''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutton.FileBrowseButton(parent, labelText, fileMas……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2610浏览 957个赞
python3 短网址和数字的相互转换import mathimport decimal def convert_to_code(num): """ 将数字转换为代码 """ def get_num(num, out=''): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1971浏览 2377个赞
python输出当前目录下的index.html文件路径import osimport sys path = os.path.join(os.path.dirname(sys.argv[0]), 'index.html')print path……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2309浏览 467个赞
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) ]……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3032浏览 2949个赞
下面的代码通过自定义一个继承自threading.Thread的类来实现多线程编程,调用非常简单import threading import time class timer(threading.Thread): #The timer class is derived from the class threading.Thread ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2587浏览 317个赞
python通过urllib2发送带cookie的求情import urllib2opener = urllib2.build_opener()opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))f = opener.open(&quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2218浏览 1322个赞
这里实现的是针对网关的欺骗。假如说,你要攻击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……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1624浏览 1588个赞
python在windows下操作word的方法import win32comfrom win32com.client import Dispatch, constantsw = win32com.client.Dispatch('Word.Application')# 或者使用下面的方法,使用启动独立的进程:# w = ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1859浏览 758个赞
python arp欺骗伪造网关代码转自:http://www.cnblogs.com/lovedboy/#coding:utf-8'''arp欺骗局域网pc,将伪造的网关mac以网关的arp应答发送给pc'''from scapy.all import ARP,send,arpin……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2678浏览 1281个赞