php生成年月日下载列表function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval) { if(empty($mval)) $mval = date("m"); if(……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3091浏览 0评论1720个赞
php格式化电话号码,这个函数只适用于美国电话,中国电话需要自己修改一下function format_phone($phone){ $phone = preg_replace("/[^0-9]/", "", $phone); if(strlen($phone) == 7) return preg_……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1900浏览 0评论2162个赞
PHP 设置cookie所有子域名共享php_value session.cookie_domain ".churchplanterprofiles.com"……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3889浏览 0评论2347个赞
php CodeIgniter检查数据库连接是否正确/** * Check Database Connection * * Checks connection details to see if they are correct. Useful for testing * user supplied details in an install……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2888浏览 0评论1601个赞
用在服务器上提供下载的php代码,可以指定被下载的文件名,可以动态指定文件内容// local file that should be send to the client$local_file = 'test.zip';// filename that the user gets as default$download_fi……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2365浏览 0评论2238个赞
这段php代码定义了两个函数 str_prefix和str_suffix,分别用来给字符串前后添加指定数量的符号function str_prefix($str, $n=1, $char=" "){ for ($x=0;$x<$n;$x++){ $str = $char . $str; } return $s……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1383浏览 0评论2920个赞
一个php实现的简单语法高亮显示的函数,注意:这个函数设计的比较简单,可能对某些语法不能高亮显示,你可以自己扩充该函数的功能function syntax_highlight($code){ // this matches --> "foobar" <-- $code = preg_replace(……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2401浏览 0评论1076个赞
对于一个长字符串,如果你只希望用户看到头尾的部分内容,隐藏掉中间内容,你可以使用这个php函数,他可以指定要隐藏掉的中间字符串的数量/** * Reduce a string by the middle, keeps whole words together * * @param string $string * @param int $max……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1905浏览 0评论1135个赞
使用php独有的array_map函数遍历清除数组中所有字符串的两端空格/** * Trims a entire array recursivly. * * @author Jonas John * @version 0.2 * @link http://www.jonasjohn.de/snippets/p……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2934浏览 0评论493个赞
交换两个变量的值在所有语言中都是最基础的算法,一般都需要一个临时变量,此php代码只用一行实现这个功能,虽然代码只有一行,但是php内部做的工作应该一点也不少list($a,$b) = array($b,$a);……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2950浏览 0评论541个赞
一个自定义的php数组元素随机调换的函数,php已经有一个内置的同样功能的函数shuffle($Array),这个代码权当参考// I noticed that there is already a built-in function that// does the same - so don't use mine ;-)//// --……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2201浏览 0评论2823个赞
这个php函数用来删除文件中的重复行,还可以指定是否忽略大小写,和指定换行符/** * RemoveDuplicatedLines * This function removes all duplicated lines of the given text file. * * @param string * @param bo……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2512浏览 0评论948个赞
删除数组里的所有空值元素,包含空字符串,空的数组等等function array_remove_empty($arr){ $narr = array(); while(list($key, $val) = each($arr)){ if (is_array($val)){ $val = array……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1768浏览 0评论2926个赞
一个php操作mysql数据库的类<?php /** * Database class * * @version: 2.2 * @author: Emil T. Kampp <emil@kampp-productions.dk> * @revised: 27 may 2007 * **/ class Data……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3248浏览 0评论373个赞
php计算两个坐标(经度,纬度)之间的距离,返回结果为米或者千米function distance($lat1, $lng1, $lat2, $lng2, $miles = true){ $pi80 = M_PI / 180; $lat1 *= $pi80; $lng1 *= $pi80; $lat2 *= $pi80; $lng2 *= ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2093浏览 0评论1218个赞
一个php编写的xml分析类************************************************************************Example:************************************************************************ $xml……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2122浏览 0评论667个赞
php获得用户的真实ip函数function getRealIpAddr(){if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet{ $ip=$_SERVER['HTTP_CLIENT_IP'];}elseif (……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2755浏览 0评论2403个赞
这是一个用于登录的php类,包含了数据库调用,写入cookieclass Auth{ var $user_id; var $username; var $password; var $ok; var $salt = "34asdf34"; var $domain = ".domain.com"; ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2987浏览 0评论2349个赞
Python生成不重复随机数的简单方法print random.sample(from,to) 例如:生成1-100之间的不重复随机数random.sample(1,100)……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1380浏览 1599个赞
python中字符串自带的split方法一次只能使用一个字符对字符串进行分割,但是python的正则模块则可以实现多个字符分割import rere.split('-|_','sharejs_haotu-icon100') 输出结果如下……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2471浏览 1535个赞
这段python代码对xapian的部分操作进行了简单的封装,希望对大家有用。import xapian, configfrom mmseg.search import seg_txt_2_dictclass Xapian(): """xapian search class """……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1472浏览 1396个赞
xapian创建索引和搜索的简单范例程序,代码使用python实现 创建索引代码import sysimport osimport errnofrom contextlib import closingimport xapian as _xdef main(file……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2297浏览 122个赞
这是一段简单的python代码,用户转换不同单位的温度,适合初学者参考6061626364656667686970717273747576def c2f(t): return (t*9/5.0)+32def c2k(t): return t+273.15def f2c(t): return (t-32)……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3204浏览 2203个赞
python编写的超简单端口转发程序代码非常简单,实现了简单的端口数据转发功能,用于真实环境还需要再修改一下。转自:http://blog.csdn.net/qffhq#tcp server import socket host = '127.0.0.1' #Local Server IP h……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2916浏览 706个赞
xapian 通过python创建索引数据库的复杂一些的范例除了包含索引字符串外,还为索引添加了两个值#!/usr/bin/env python## Index each paragraph of a text file as a Xapian document.# Include some values that will be of use……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2318浏览 1188个赞
这段代码需要调用serial模块,通过while循环不断读取串口数据转自:http://www.yelinsky.com/import timeimport serialser = serial.Serial( #下面这些参数根据情况修改 port='COM1', baudrate=9600, par……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2529浏览 1823个赞
python通过BF算法实现关键词匹配作者:smalltt#!/usr/bin/python# -*- coding: UTF-8# filename BFimport time"""t="this is a big apple,this is a big apple,this is a big ap……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2744浏览 2917个赞
python利用asyncore的端口映射(端口转发)可以实现端口数据的转发,效果还是不错的代码转自:http://www.cnblogs.com/nethirteimport socket,asyncoreclass forwarder(asyncore.dispatcher): def __init__(self, ip, port……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2645浏览 2395个赞
python读写文件方法汇总转自:http://blog.csdn.net/adupt/archive/2009/08/11/4435615.aspx 1.open使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2155浏览 271个赞
python getaddrinfo() 基本使用代码import sys, socketresult = socket.getaddrinfo("192.1.1.100", None)print result[0][4]print result 输出结……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2750浏览 2017个赞
这段代码可以生成5个不同的随机字母组成的长度为8的字符串import random, string for c in range(5): print random.sample(string.letters+string.digits, 8)……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2624浏览 716个赞
python实现一个简单的基于SSL的 IRC bot的代码#!/usr/bin/python# -*- coding: utf8 -*- import socket, string, time, sslimport urllib, re network = 'irc.server.net'nick = 'n……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2081浏览 2419个赞
使用urllib和正则抓取和分析网页的简单代码片段import urllib, re url = 'http://www.viedemerde.fr/aleatoire'page = urllib.urlopen(url).read()parse = re.findall("\<div class=\&quo……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2443浏览 2944个赞
python编写的简单RPG游戏流程代码#RPGrpg = Truewhp = 100mahp = 100hhp = 100MHP = 10 def dgrnd () : wa = raw_input ("What does Warrior do?") ma = raw_input ("Wha……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2633浏览 1001个赞
将代码生成.py文件放在目录下运行,可以获取该目录的所有mp3文件的信息,需要使用ID3库import os, sysfrom ID3 import * files = os.listdir(os.getcwd()) for f in files: x = os.path.splitext(f) if x[1] == ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2354浏览 1770个赞
python将html表格转换成CSV使用方法:python html2csv.py *.html这段代码使用了 HTMLParser 模块#!/usr/bin/python# -*- coding: iso-8859-1 -*-# Hello, this program is written in Python - http://python.o……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1929浏览 2207个赞
python根据主机名字获得所有ip地址# -*- coding: utf-8 -*-import sys, socketresult = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM)counter = 0for item in resul……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2479浏览 974个赞
一个简单python ftp客户端代码#!/usr/bin/python# -*- coding: utf-8 -*-import ftplibimport osimport socketHOST = 'ftp.mozilla.org'DIRN = 'pub/mozilla.org/webtools'……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3247浏览 2673个赞
一段简单的python邮件客户端发送代码#/usr/bin/python# -*- coding: utf-8 -*-import reimport smtplibfrom poplib import POP3from email.mime.text import MIMETextdef sevname(username): pa ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2443浏览 1368个赞
python实现自动登录人人网并采集信息的代码#!/usr/bin/python# -*- coding: utf-8 -*-import sysimport reimport urllib2import urllibimport cookielibclass Renren(object): def __init__(se……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2839浏览 916个赞
python代码用于查找指定具有相同内容的文件,可以同时指定多个目录调用方式:python doublesdetector.py c:\;d:\;e:\ > doubles.txt# Hello, this script is written in Python - http://www.75271.com# doublesdetector.py 1……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1998浏览 1078个赞
python Gevent multiprocessing serverimport sysfrom gevent import serverfrom gevent.baseserver import _tcp_listenerfrom gevent.monkey import patch_all; patch_all()from multi……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3328浏览 509个赞
一个使用进程内通讯的python聊天室代码,非常简单的服务端和客户端代码#!/usr/bin/env python# Added by <ctang@redhat.com>import sysimport osfrom multiprocessing import connectionADDR = ('', 9……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2825浏览 1342个赞
这段代码可以对指定的目录进行扫描,包含子目录,对指定扩展名的文件进行SHA-1加密后存储在cvs文件,以防止文件被篡改调用方法:python snapper.py > todayCheck.csv# Hello, this is a script written in Python. See http://www.pyhon.org## Snapp……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2046浏览 483个赞
我用这段代码来压缩数据库备份文件,没有使用python内置的zip模块,而是使用了zip.exe文件# Hello, this script is written in Python - http://www.75271.com## autozip.py 1.0p## This script will scan a directory (and……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2777浏览 2821个赞