修改一下第二行的url地址即可获得你想要的网页的html代码<?php // display source code $lines = file('http://google.com/'); foreach ($lines as $line_num => $line) { // loop thru e……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2779浏览 0评论449个赞
php版快速排序代码function quicksort($seq){ if(!count($seq)) return $seq; $k = $seq[0]; $x = $y = array(); for($i=count($seq); --$i;) { if($seq[$i] <= $k) { $x[] = $……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2030浏览 0评论2533个赞
jQuery读写操作cookie的代码演示,可以对cookie进行读写操作,可以设置域名和过期时间 插件代码/*! * jQuery Cookie Plugin v1.3 * https://github.com/carhartl/jquery-cookie * * Cop……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3130浏览 0评论207个赞
这段代码可以帮助你判断任意图片的主色调,使用了简单的统计算法实现$i = imagecreatefromjpeg("image.jpg"); for ($x=0;$x<imagesx($i);$x++) { for ($y=0;$y<imagesy($i);$y++) { $rg……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1507浏览 0评论625个赞
需要判断代码运行环境是否是HTTPS服务器,只需要判断_SERVER[‘HTTPS’]是否打开即可if ($_SERVER['HTTPS'] != "on") { echo "This is not HTTPS"; }else{ echo &……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2425浏览 0评论705个赞
php实现二分查找算法// $low and $high have to be integersfunction BinarySearch( $array, $key, $low, $high ){ if( $low > $high ) // termination case { return -1; ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2971浏览 0评论2357个赞
php检查日期是否合法function check_date($date) { //检查日期是否合法日期 $dateArr = explode("-", $date); if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) &&……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1831浏览 0评论2871个赞
php自己实现memcached的队列类<?php/* * memcache队列类 * 支持多进程并发写入、读取 * 边写边读,AB面轮值替换 * @author lkk/lianq.net * @create on 9:25 2012-9-28 * * * @example: * $obj = new memcacheQu……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1438浏览 0评论950个赞
php无限分类获得当前位置的函数<?php/* * @name pcb_article_position * @access public * @param int $id * @param string $split * @return string */function pcb_article_position ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2301浏览 0评论684个赞
php获取访问者浏览器<? function browse_infor() { $browser="";$browserver=""; $Browsers =array("Lynx","MOSAIC","AOL","Opera&q……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2969浏览 0评论382个赞
php检查时间是否合法function check_time($time) { //检查时间是否合法时间 $timeArr = explode(":", $time); if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) &&am……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2966浏览 0评论2835个赞
php时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天 function DateDiff($date1, $date2, $unit = "") { //时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天 switch ($unit) { case 's': ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3295浏览 0评论1087个赞
php把全角数字转换为半角数字<? function GetAlabNum($fnum){ $nums = array("0","1","2","3","4","5","6","……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2450浏览 0评论1380个赞
php重定向的三种方法<? 方法一:header("Location: index.php"); 方法二:echo "<scrīpt>window.location ="$PHP_SELF";</scrīpt>"; //OSPHP.COm.CN 方法三:ec……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2938浏览 0评论1882个赞
php写入文件函数<? function writetofile($file_name,$data,$method="w") { $filenum=fopen($file_name,$method); //OSPHP.COM.Cn开源 flock($filenum,LOCK_EX); $file_data=fwrite……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2847浏览 0评论992个赞
php相对路径转换成绝对路径<? function relative_to_absolute($content, $feed_url) { preg_match('/(http|https|ftp):///', $feed_url, $protocol); $server_url = preg_rep……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1923浏览 0评论448个赞
php取得网页上的所有链接<? function get_all_url($code){ preg_match_all('/<as+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)</……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3541浏览 0评论2437个赞
php去除html标记<? function Text2Html($txt){ $txt = str_replace(" "," ",$txt); $txt = str_replace("<","<",$txt); ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1691浏览 0评论2717个赞
php生成excel文档<? header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=test.xls"); echo "test1t"; echo "t……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2678浏览 0评论2435个赞
php获取访问者的操作系统信息<? function osinfo() { $os=""; $Agent = $GLOBALS["HTTP_USER_AGENT"]; if (eregi('win',$Agent) && strpos($Agent, '……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2270浏览 0评论372个赞
php删除指定的目录,本代码会递归删除子目录<?php/** * Delete a file, or a folder and its contents (recursive algorithm) * * @author Aidan Lister <aidan@php.net> * @version 1.0……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1965浏览 0评论2502个赞
这段代码可以自动根据post数组的键值创建同名变量,这个功能使用非常方便,不用提前声明变量<?php$expected=array('username','age','city','street');foreach($expected as $key){ ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2236浏览 0评论2646个赞
php简单截断字符串函数,如果截断在字符串后自动加上省略号function short($txt,$size){ $short = $size - 3; if(strlen($txt) > $size){ $data = substr( $txt, 0, $short )."..."; ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2214浏览 0评论224个赞
将HTML表格的每行每列转为数组,采集表格数据<? function get_td_array($table) { $table = preg_replace("'<table[^>]*?>'si","",$table); //oSPHP.COM.C……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2629浏览 0评论1801个赞
php获取当前urlfunction curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; i……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2840浏览 0评论2308个赞
返回字符串中的所有单词 $distinct=true 去除重复<? function split_en_str($str,$distinct=true) { preg_match_all('/([a-zA-Z]+)/',$str,$match); if ($distinct == true……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1609浏览 0评论2102个赞
php将12小时制转换成24小时制,输入格式为:02:30:00 pm 转换成:14:30:00<?phpfunction to_24_hour($hours,$minutes,$seconds,$meridiem){ $hours = sprintf('%02d',(int) $hours); $minut……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1790浏览 0评论1939个赞
javascriipt通过当前时间解决GET和POST的缓存问题在postUrl后面添加当前时间为参数,可以有效的解决缓存问题因为每次提交的url地址都是不同的var currentTime = new Date();var n = currentTime.getTime();postUrl = "http://www.example.c……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2520浏览 0评论2269个赞
Sum all elements of a bidimensional or multi-dimensional array with an assigned key/** * sum values in array * * @param array $arr * @param string [optional]$index * @retur……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1459浏览 0评论1020个赞
简单的PHP框架,实现antoload,viewEngine,有兴趣学写MVC框架的可以看看这篇文章: http://my.oschina.net/u/131802/blog/82016 这个很适合初学者对框架的认识 index.php 入口文件<?php……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1972浏览 0评论2791个赞
360提供的php防注入代码<?php //Code By Safe3 function customError($errno, $errstr, $errfile, $errline) { echo "<b>Error number:</b> [$errno],error on line $……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2670浏览 0评论1120个赞
根据给定的数字查找其因数的高效C++代码//Algorithm derived from the method described here://http://mathschallenge.net/index.php?section=faq&ref=number/number_of_divisorsint mathTools::numFac……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3204浏览 0评论288个赞
php实现的ssh api类,主要用来通过ssh传输文件class SshApi extends BaseObject{ public $session = null; public $authenticated = false; public function __construct(){ } p……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2983浏览 0评论1553个赞
php遍历目录的代码<?php function myscandir($pathname){ foreach( glob($pathname) as $filename ){ if(is_dir($filename)){ myscandir($filename.……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2816浏览 0评论1632个赞
简单的php正则校验email地址的函数<?php /* If you won't use filter_var() you should use this instead */ function isEmail($email) { if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-z……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1509浏览 0评论2470个赞
Android通过HttpClient执行post请求public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = n……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3379浏览 0评论2821个赞
指定原始字符串,给定开始和结尾字符串,获得这两个字符串之间的子字符串的php函数/** * Returns the substring between two strings, delimiters not included * @param string $string Haystack * @param string $start Start……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2160浏览 0评论1199个赞
一个文件大小单位格式化的php函数,如 echo format_size(filesize(“fichier”)); 输出:13,37 Ko<?php/* Use : echo format_size(filesize("fichier"));Example result : 13,37 Ko */……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2837浏览 0评论1504个赞
php打水印函数function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3048浏览 0评论1498个赞
php给一组指定的关键词添加span标签,高亮突出显示关键词// Example use: $spanned = codeWords($string_containing_keywords);// My site: andrew.dx.am// Using colour==blue, but different arrays of words an……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2838浏览 0评论1728个赞
php Query posts and cache the query$bandeau_post = get_transient('top1_bandeau_post'); if (!is_array($bandeau_post) || count($bandeau_post)==0) { ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3158浏览 0评论998个赞
php从map删除指定的元素并返回一个新的mapval origMap = Map("key1" -> "something", "key2" -> "else");val myMap = origMap - "key1";//myMap……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3887浏览 0评论1813个赞
与大多数流行的 Web 服务如 Twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。$json_string='{"id":1,"name":"foo","email":"f……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2767浏览 0评论1632个赞
php删除整个目录的代码/******@dir - Directory to destroy*@virtual[optional]- whether a virtual directory*/function destroyDir($dir, $virtual = false){ $ds = DIRECTORY_SEPARATOR;……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3097浏览 0评论2768个赞
php将字符串中的url转换成超级链接function makeClickableLinks($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1">……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3135浏览 0评论933个赞