Android下通过HttpClient执行 HTTP POST 请求 public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost ht……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3114浏览 1900个赞
这段php代码定义了一个两个数相加的函数,调用后输出函数运行结果。<html><head><title>Writing PHP Function with Parameters</title></head><body><?phpfunction addFunct……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2520浏览 1599个赞
这里自定义了一个函数用于将zip文件解压缩,可以指定解压缩的路径<?php function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2480浏览 1815个赞
我们可以通过HTTP_USER_AGENT来判断是否是蜘蛛,搜索引擎的蜘蛛都有自己的独特标志,下面列取了一部分。function is_crawler() { $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); $spiders = array( ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3248浏览 2667个赞
php通过POST方式提交表单信息代码范例,php中通过$_POST变量获得表单post上来的信息,$_PHP_SELF表示当前页面<?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $_POST……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2915浏览 609个赞
php 四舍五入的三种方法,分别通过number_format函数、round函数和sprintf格式化输出的方法实现四舍五入 1.number_format 方法实现四舍五入$number = 1234.5678; $nombre_format_fran……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1954浏览 479个赞
PHP中 $_REQUEST变量包含了$_GET、$_POST和$_COOKIE三个变量的所有值无论用户通GET还是POST方式提交表单,我们都可以通过$_REQUEST变量获取表单值下面的php代码详细演示了$_REQUEST变量的用法<?php if( $_REQUEST["name"] || $_REQUEST[……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1537浏览 138个赞
这段php代码使用while语句循环对变量$i进行累加,当$i=3时退出循环<html><body><?php$i = 0;while( $i < 10){ $i++; if( $i == 3 )break;}echo ("Loop stopped at i = $i"……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3118浏览 2494个赞
这段php代码通过foreach语句遍历数组,当遍历到数组元素值等于3时跳过循环体后面的语句,继续执行下一次循环<html><body><?php$array = array( 1, 2, 3, 4, 5);foreach( $array as $value ){ if( $value == 3 )conti……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2275浏览 2219个赞
php中可以通过$_PHP_SELF变量表示当前页面,下面的代码通过将表单的action设置为$_PHP_SELF变量将表单信息提交到当前页面<?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1403浏览 1756个赞
这段php代码定义了一个二维数组用于存储学生的学科成绩,代码演示了如何定义和使用二维数组<html><body><?php $marks = array( "mohammad" => array ( "physics" => 35, ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1325浏览 810个赞
php通过GET方式提交表单演示,$_PHP_SELF表示当前页面,php中通过$_GET变量获得用户提交的信息<?php if( $_GET["name"] || $_GET["age"] ) { echo "Welcome ". $_GET['name&……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2106浏览 1953个赞
php返回当前日期或者指定日期是星期几 PHP星期几获取代码:date("l"); //data就可以获取英文的星期比如Sundaydate("w"); //这个可以获取数字星期比如123,注意0是星期日 ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1625浏览 284个赞
php检测客户端浏览器类型代码<html><body><?php $viewer = getenv( "HTTP_USER_AGENT" ); $browser = "An unidentified browser"; if( preg_match( "……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2330浏览 1593个赞
php提交表单后页面重定向代码,这段代码提交表单到当前页面,提交后通过设置header进行页面重定向,exit()函数可以让代码强行退出不执行后面的代码<?php if( $_POST["location"] ) { $location = $_POST["location"]; ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2848浏览 1331个赞
这段php代码通过两种不同的方式创建php数组,并通过foreach语句分别遍历两个数组输出<html><body><?php/* First method to create array. */$numbers = array( 1, 2, 3, 4, 5);foreach( $numbers as $valu……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1693浏览 579个赞
php通过rand()函数产生随机数,这个函数可以产生一个指定范围的数字这段代码通过产生的随机数,随机选择图片<html><body><?php srand( microtime() * 1000000 ); $num = rand( 1, 4 ); switch( $num ) { c……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2281浏览 352个赞
这段php代码通过do while语句对变量$i进行累加<html><body><?php$i = 0;$num = 0;do{ $i++;}while( $i < 10 );echo ("Loop stopped at i = $i" );?></body&g……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2133浏览 2809个赞
php根据生日计算年龄<?php function birthday($birthday){ $age = strtotime($birthday); if($age === false){ return false; } list($y1,$m1,$d1) = explode(&quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2669浏览 320个赞
本代码根据定义好的php数组动态生成一个html的下拉列表(select)<?php //Array contents array 1 :: value $myArray1 = array('Cat','Mat','Fat','Hat'); //Array co……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2083浏览 1313个赞
此代码会从指定的服务器文件夹随机选择一个图片进行显示,非常有用,图片格式为.gif,.jpg,.png<?php //This will get an array of all the gif, jpg and png images in a folder $img_array = glob("/path/to/images/*.{……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3027浏览 2201个赞
本代码可以根据用户输入的英文姓名,分析出姓名的首字母输出,比如”Billy Bob” to “B.B.”<?php function initials($name){ $nword = explode(" ",$name); foreach($nword a……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1531浏览 2646个赞
这是一个经常用到的功能,如果字符串太长,需要按照指定的长度进行截断,然后在后面加上三个点的省略号<?php //if a string is longer than the defined length, //it will add 3 periods to the end of the string. //you can change ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3119浏览 1726个赞
一个简单的php生成的图片验证码,带表单,验证码生成代码,以及验证程序image.php<?php header("Content-type: image/png"); $string = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2656浏览 909个赞
php汉字转换成拼音的代码类<?phpfunction Pinyin($_String, $_Code='UTF8'){ //GBK页面可改为gb2312,其他随意填写为UTF8 $_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2736浏览 2180个赞
php计算一个文件的大小<?php function dirSize($directoty){ $dir_size=0; if($dir_handle=@opendir($directoty)) { while($filename=readdir($dir_handle)){ ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2780浏览 2127个赞
php上传图片的同时生成缩略图<?php function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){ $details = getimagesize("$imageDirectory/$image……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3039浏览 1963个赞
列出目录的全部子目录,存储在数组里<?php function listdir($dir){ if ($handle = opendir($dir)){ $output = array(); while (false !== ($item = readdir($handle))){ ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3106浏览 939个赞
一个简单的php获得文件扩展名的方法,如:.php<?php $file = '/path/to/file.php'; $info = pathinfo($file); echo $info['extension']; ?>……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2227浏览 1159个赞
PHP面向对象实现数据库登陆的类代码 db_class.php类的实现代码:<?php class dbclass { public $connection ; public $result ; public $fetch_num ;……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2165浏览 376个赞
php获取post过来的xml数据并解析 php 如何获取请求的xml数据,对方通过http协议post提交过来xml数据,php如何获取到这些数据呢?<?php $xml_data ='<AATAvailReq1>'. ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2922浏览 2918个赞
大部分计算机软件支持的是RGB格式的颜色,但是HSL会更加人性化,下面的代码实现了rgb和hsl的相互转换def HSL_to_RGB(h,s,l): ''' Converts HSL colorspace (Hue/Saturation/Value) to RGB colorspace. Form……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2065浏览 855个赞
Linux系统下php获得系统分区信息的代码$pars = array_filter(explode("\n",`df -h`)); foreach ($pars as $par) { if ($par{0} == '/') { $_tmp = array_values(ar……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1612浏览 331个赞
本代码演示了php中如何使用转义字符<?php print("<font color=\"red\">Red text</font>"); ?> ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2069浏览 2910个赞
当我们在接受未知客户端提交的数据,由于各客户端的编码不统一,但在我们的服务器端最终只能以一种编码方式来处理,这种情况下就会涉及到编码转换问题// 自动转换字符集 支持数组转换 function auto_charset($fContents, $from='gbk', $to='utf-8') { $from……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1488浏览 449个赞
php调用万网接口实现域名查询 今天给别人做网站时有个需求是要有域名查询功能,查了点资料写了个简单的查询功能 前台页面用的是checkbox,代码如下:<form name="form1" method="post" ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1712浏览 2972个赞
使用python打包你的整个Gmail邮箱,需要Gmail打开IMAP服务#!/usr/bin/python# -*- coding: iso-8859-1 -*-""" GMail archiver 1.1This program will download and archive all you emails f……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3469浏览 784个赞
在PHP编程中,递归调用常常与静态变量使用。静态变量的含义可以参考PHP手册.希望下面的代码,会更有利于对递归以及静态变量的理解<?php //下面代码会画出一个很漂亮的叶子 // 定义 PI 一分的角度的值 define("PII", M_PI/180); // 新建图像资源,并定义其背景为 白色,前景色为 黑色 ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2337浏览 607个赞
python通过urllib2发送post请求并抓取返回内容#!/usr/bin/pythonimport urllib,urllib2url = 'http://www.commentcamarche.net/search/search.php3'parameters = {'Mot' : 'G……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2398浏览 2602个赞
本代码通过查询那些提供ip地址查看的网站获取你自己的真实ip地址,如果你当前离线,则返回None范例:>>> print public_ip()85.212.182.25import urllib,random,reip_regex = re.compile("(([0-9]{1,3}\.){3}[0-9]{1,3})")def……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2141浏览 1034个赞
php计算指定目录(包含子目录)的完整大小/** * Calculate the full size of a directory * * @author Jonas John * @version 0.2 * @link http://www.jonasjohn.de/snippets/php/dir-siz……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1466浏览 2790个赞
一个通过break语句终止php循环的例子$max_loop=5; //This is the desired value of Looping$count = 0; //First we set the count to be zeoecho "<h2> Here goes the values</h2>&quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2390浏览 1408个赞
php对字符串在指定的长度范围内进行随机分割,把分割后的结果存在数组里面function RandomSplit($min, $max, $str){ $a = array(); while ($str != ''){ $p = rand($min, $max); $p = ($p……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3044浏览 2865个赞
对文件夹和文件递归之行chmod命令来改变执行权限<? function recursiveChmod($path, $filePerm=0644, $dirPerm=0755) { // Check if the path exists if(!file_exists($path)) { ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2123浏览 2423个赞
自动匹配页面里的网址,包含http,ftp等,自动给网址加上链接function text2links($str='') { if($str=='' or !preg_match('/(http|www\.|@)/i', $str)) { return $str; } ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2605浏览 1910个赞