使用PHP进行字符串循环$string = "Your String";for($i=0;$i<strlen($string);$i++){ $char = substr($string,$i,1);} ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2890浏览 2489个赞
批量去除UTF8的Bom标签#!/usr/bin/python#coding=utf-8import osimport sysimport codecsclass RemoveBom: basePath = '' fileList = [] trimExtList = [] ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2746浏览 1499个赞
这是一个函数定位接收一个字符串作为参数(连同其他配置可选参数),并且定位该字符串中的所有关键字(出现最多的词),返回一个数组或一个字符串由逗号分隔的关键字。功能正常工作,但我正在改进,因此,有任何的建议请评论。/** * Finds all of the keywords (words that appear most) on param $str ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1784浏览 561个赞
背包问题描述:一个承受最大重量为W的背包,现在有n个物品,每个物品重量为t, 每个物品的价值为v。 要使得这个背包重量最大(但不能超过W),同时又需要背包的价值最大。 转自:http://blog.csdn.net/oceanwavewyt/article/details/4479498<? /***背包问题描述:一个承受最大重量为W的背包,现……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3595浏览 496个赞
根据《软件设计师》教程的伪代码写的;最麻烦的不是伪代码改成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) 3153浏览 1684个赞
给出两个数值X和Y,统计在这个区间里的回文数,并且要求它们的平方根也是回文数。其中 1……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2633浏览 285个赞
“回文数”是一种数字。如:98789, 这个数字正读是98789,倒读也是98789,正读倒读一样,所以这个数字就是回文数。<?php for($i=10;$i<100;$i++){ $len=strlen($i); $l=1; $k=intval($len)/2+1; ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1900浏览 1656个赞
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……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1736浏览 1405个赞
php在网页上将mysql数据转换到excel输出的代码<?php$DB_Server = "localhost";$DB_Username = "mydowns";$DB_Password = "";$DB_DBName = "mydowns";$DB_TB……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1645浏览 2708个赞
php导出CSV文件代码,可供Excel读取<?php// 这里要注意包含类路径要正确require_once(dirname(__FILE__) . '/export.php');$exceler= newJason_Excel_Export(); // 生成excel格式 这里根据后缀名不同而生成不同的格式。$e……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1693浏览 2766个赞
php通过com连接excel并输出数据<?php//定义一个excel文件$workbook = "C:/My Documents/test.xls";$sheet = "Sheet1";//生成一个com对象$ex$ex = new COM("Excel.sheet") or……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3312浏览 1991个赞
贪心算法解决0-1背包问题,全局最优解通过局部最优解来获得!比动态规划解决背包问题更灵活!//0-1背包贪心算法问题class tanxin{ public $weight; public $price; public function __construct($weight=0,$price=0) { $this->weight=$……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2758浏览 1996个赞
php丽娜姐到mysql数据库并进行简单的查询过程演示<?php$DB_HOST = "localhost";$DB_NAME = "db";$DB_USER = "user";$DB_PASSWORD = "pass";$con = mysql_connec……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2240浏览 2176个赞
PHP连接到Mongodb的方法 下面的代码直接链接到本地mongdb服务器,端口使用默认的27017$connection = new Mongo(); 下面的代码链接到172.20.10.8的mong……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2937浏览 2411个赞
在php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel的文件,使用excel打开就会看到最终的结果,怎么样不错吧。 其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加\t,每一行数据结束后加\n的方法echo出来,在php的开头用header(“Co……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2744浏览 1602个赞
默认情况下scrapy采集时只能使用一种user-agent,这样容易被网站屏蔽,下面的代码可以从预先定义的user-agent的列表中随机选择一个来采集不同的页面 在settings.py中添加以下代码DOWNLOADER_MIDDLEWARES = { ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 5884浏览 2260个赞
php写入数据到CSV文件范例代码<?php$row = 0;ini_set('max_execution_time', 300);$cate;$item;$value;$us;$fp = fopen("torah1.csv", "w");if (($handle = fope……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2229浏览 1841个赞
php列出当前目录下的所有php文件<?php//Define directory for files listing//original example//$files = glob('/path/to/dir/*.xml');$files = glob('*.php');//to limit ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2765浏览 1250个赞
这段代码判断当前日期是星期几,根据返回值输出Today is Monday的字样,使用switch语句记得每个case后面跟着一个break语句<html><body><?php$d=date("D");switch ($d){case "Mon": echo &qu……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2881浏览 2209个赞
很多网站,比如twitter,京东商城首页,会在页面滚动到一定的位置时才动态加载页面内容,这样可以加快页面打开的速度,也可以节约带宽,下面的JS代码就可以帮你做到。var loading = false;$(window).scroll(function(){ if((($(window).scrollTop()+$(window).height(……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1912浏览 1767个赞
php中可以通过define函数定义常量,调用的时候可以直接使用常量名称也可也使用constant函数调用,下面的例子详细演示了php中常量的使用方法。<?phpdefine("MINSIZE", 50);echo MINSIZE;echo constant("MINSIZE"); // same……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3285浏览 1029个赞
下面的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……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3625浏览 556个赞
这段代码使用while语句对两个变量$i和$num分别进行递减和递加<html><body><?php$i = 0;$num = 50;while( $i < 10){ $num--; $i++;}echo ("Loop stopped at i = $i and num = ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3072浏览 398个赞
如果当前日期是星期五下面的代码返回“Have a nice weekend!”,否则返回 “Have a nice day!”<html><body><?php$d=date("D");if ($d=="Fri") echo "Have……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3027浏览 503个赞
做站点时,通常要将图片缩小成合适的尺寸,jpg图片缩小比较容易,png图片如果带了透明色的话,按照jpg的方式来缩小的话,就会造成透明色损失。那么如何处理,才能保存透明色呢?主要是利用gd库的两个方法:imagecolorallocatealpha 分配颜色 + alphaimagesavealpha 设置在保存 png 图像时保存完整的 alpha ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2224浏览 1633个赞
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……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1756浏览 2511个赞
下面的php代码用于测试给定密码的强度,最高强度为100<?php /** * * @param String $string * @return float * * Returns a float between 0 and 100. The closer the number is to 100 the * th……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1693浏览 638个赞
php单件模式实现代码演示<?php/** * @link https://github.com/MaGuowei * @copyright 2013 maguowei.com * @author Ma Guowei <imaguowei@gmail.com> */ /** * 单例模式 * Class Single……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2618浏览 802个赞
通过下面的jQuery插件,你可以将图片放在一个数组里,然后告诉jQuery图片需要在什么地方背景轮换/*** jQuery Fading background roator** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3616浏览 2629个赞
php检测apache mod_rewrite模块是否安装/** * @title Check if Apache's mod_rewrite is installed. * * @author Pierre-Henry Soria <ph7software@gmail.com>……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1671浏览 2729个赞
下面的jQuery插件允许你通过鼠标右键点击拖动overflow的元素,这个插件可以在移动设备上运行/*** jQuery Drag and Scroll** Copyright (c) 2012 Ryan Naddy (ryannaddy.com)* Dual licensed under the MIT and GPL licenses:……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1825浏览 2753个赞
php利用反射实现插件机制的代码<?php /** * @name PHP反射API--利用反射技术实现的插件系统架构 * @author :PHPCQ.COM */ interface Iplugin{ public static function getName(); } funct……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2682浏览 329个赞
下面的php代码可以对电子邮件地址进行简单验证和强验证,简单验证验证邮件格式和主机是否存在,强验证会连接邮件服务器进行验证,需要比较长时间<?php /* * __construct($email) takes an email address to check * * simpleCheck() ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2332浏览 746个赞
一个自定义的php分页类代码<?phpclass Pagination{ // Default values var $items = -1; var $limit = NULL; var $target = ""; var $page = 1; var $adjacents = 1; var $showC……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3027浏览 1926个赞
PHP定时执行任务的实现ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{ //这里是你要执行的……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3449浏览 744个赞
这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,例如:1332888820 格式转换成 2012-03-28 06:53:40的形式# -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1978浏览 626个赞
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……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3599浏览 2017个赞
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……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1854浏览 926个赞
python从url中获取文件名import urllib2 file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2514浏览 1030个赞
python中带有zlib库可以用来对数据进行压缩和解压缩,针对大量数据可以节省不少的空间import zlibdata='hello world'data = zlib.compress(data)#压缩#data此时的值为:'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2940浏览 2868个赞
python将文本转换成图片输出#-*- coding:utf-8 -*- from PIL import Image,ImageFont,ImageDraw text = u'欢迎访问脚本分享网,http://www.75271.com' font = ImageFont.truetype("msyh……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3281浏览 2296个赞
python通过wxPython打开并播放wav文件''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutton.FileBrowseButton(parent, labelText, fileMas……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1636浏览 2020个赞
python3 短网址和数字的相互转换import mathimport decimal def convert_to_code(num): """ 将数字转换为代码 """ def get_num(num, out=''): ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1915浏览 263个赞
python输出当前目录下的index.html文件路径import osimport sys path = os.path.join(os.path.dirname(sys.argv[0]), 'index.html')print path……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2938浏览 1835个赞
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) ]……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2968浏览 1077个赞