这段代码通过各种手段来检测用户终端是否是移动设备function mobile_device_detect($iphone=true,$ipad=true,$android=true,$opera=true,$blackberry=true,$palm=true,$windows=true,$mobileredirect=false,$desktopr……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2615浏览 1394个赞
php在当前页验证表单数据URL: http://support.jodohost.com/showthread.php?t=4350<?php function VerifyForm(&$values, &$errors){ // Do all necessary form verification i……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2627浏览 2506个赞
这个php图片上传类功能非常完善,完全可以满足各种图片上传需求<?php/************************************** seesaw associates | http://seesaw.net client: file: description: Copyright (C) 2008 M……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2843浏览 2420个赞
这段代码可以检测用户是否使用移动设备浏览网页,检验非常完整<?php $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolowe……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2870浏览 701个赞
这段代码简单的演示了php如何读取和分析xml文件//xml.xml : <?xml version="1.0" encoding="utf-8" ?><Kategorien> <Kategorie> <ID>1</ID> ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2114浏览 2464个赞
php检测给定的url地址是否存在function url_exists($url) { $hdrs = @get_headers($url); return is_array($hdrs) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$hdrs[0]……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3089浏览 295个赞
php中通过定义mysql_safe_string函数防止sql注入function mysql_safe_string($value) { if(empty($value)) return 'NULL'; elseif(is_string($value)) return '\……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2060浏览 1239个赞
这段代码提供了几个常用的正则//replace all but links/<(?!\/?a(?=>|\s.*>))\/?.*?>/g //validate url/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/ //Validate……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2422浏览 1574个赞
php链接mysql的基本方法$username="username";$password="password";$database="your_database";$table="your_table"; mysql_connect(localhost,$use……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2444浏览 2096个赞
面向对象的mysql数据库操作php类<?phpclass database { var $host = NULL; var $username = NULL; var $password = NULL; var $databaseName = NULL; var $link = NULL; var $queries = NUL……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2029浏览 2964个赞
php获取twitter最新的消息<?phpfunction get_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_ti……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2269浏览 1229个赞
一个php mysql数据库操作类,功能不是很完善,但非常有用<?phpclass Database{ private $host; private $user; private $pwd; private $rows; private $error; private $result; private $dbName; pri……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1429浏览 1075个赞
这段代码比较完整,带session写入,mysql数据库查询//escape data and strip tagsfunction safestrip($string){ $string = strip_tags($string); $string = mysql_real_escape_string($string); return $st……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2005浏览 1517个赞
一个用来遍历CSV文件的php类<?php class CSVIterator implements Iterator{ const ROW_SIZE = 4096; private $filePointer; private $currentElement; private $rowCounter; private $del……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2476浏览 2093个赞
php发送邮件函数,支持html和普通文本<?phpfunction send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body){ $eol="\n"; $mime_boundary=md5(time()); # Commo……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2130浏览 2708个赞
php返回相对时间,如:20分钟前,3天前function plural($num) { if ($num != 1) return "s";} function getRelativeTime($date) { $diff = time() - strtotime($date); if ($diff<60)……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2764浏览 510个赞
php优化mysql数据库的所有表<?php dbConnect(); // Database connection $alltables = mysql_query("SHOW TABLES"); while ($table = mysql_fetch_assoc($alltables)) { for……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2107浏览 759个赞
php计算到指定的日期还有多少天function countdays($d){ $olddate = substr($d, 4); $newdate = date(Y) ."".$olddate; $nextyear = date(Y)+1 ."".$olddate; if($newdate……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1286浏览 1455个赞
这段php代码改变了图片直接打开为下载// The php (process.php) $file = $_GET['file'];header ("Content-type: octet/stream");header ("Content-disposition: attachment; fi……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3167浏览 353个赞
在不破坏单词的情况下截断字符串/*returns text limited by a specified length of characters but keeping words intact. the final character count will not be exact since it is affected by the poss……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1473浏览 2201个赞
一个简单的php BBCode替换函数function BBcode($texto){ $a = array( "/\[i\](.*?)\[\/i\]/is", "/\[b\](.*?)\[\/b\]/is", "/\[u\](.*?)\[\/u\]/is&qu……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1844浏览 2341个赞
从给定的url中移除指定的参数,如果参数不存在,则返回原urlfunction remove_querystring_var($url, $key) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1533浏览 1474个赞
这段代码可以动态为url添加key-value查询参数,如果参数已经存在则会用新的进行覆盖function add_querystring_var($url, $key, $value) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&am……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1803浏览 2066个赞
php修改上传图片的尺寸<?php // This is the temporary file created by PHP$uploadedfile = $_FILES['uploadfile']['tmp_name']; // Create an Image from it so we can……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1460浏览 498个赞
php验证邮件地址函数<?php function validateEmail($email){ $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1840浏览 1756个赞
php得到当前页面的完整地址function full_url(){ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $p……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1842浏览 711个赞
一个非常全面的php Email地址函数function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1566浏览 1167个赞
一段简单的php生成图片水印的代码,这段代码只支持图片水印function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype ==……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1301浏览 2235个赞
php给自己发送自动备份的mysql数据表邮件<?// Create the mysql backup file// edit this section$dbhost = "yourhost"; // usually localhost$dbuser = "yourusername";$dbpas……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2078浏览 2520个赞
php记录Google机器人访问足迹<?php $email = "test@test.com"; if(eregi("googlebot",$HTTP_USER_AGENT)){ if ($QUERY_STRING != "") { $url ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2725浏览 745个赞
一段php发送邮件的代码,邮件格式可以使纯文本或者html,可以添加附件PHP: Sending Email (Text/HTML/Attachments) Email is the most popular Internet service today. A plenty of emails are sent and delivered each……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2262浏览 449个赞
通过这段代码可以判断用户的请求是否来自AJAX XMLHttpRequest,以区别普通post,get和ajaxfunction isAjax() {return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUES……继续阅读 » 水墨上仙 5年前 (2021-03-22) 4100浏览 2374个赞
这段php类可以挨个添加文件到数组,最后将添加的文件打包成zip/* $Id: zip.lib.php,v 1.1 2004/02/14 15:21:18 anoncvs_tusedb Exp $ */ // vim: expandtab sw=4 ts=4 sts=4: /** * Zip file creation class. *……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2034浏览 1774个赞
一个简单的正则表达式清理不需要的字符function setDescriptionString($inputString=""){$replacedWords = array("…","‘","ó","<ul>","<li&……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1991浏览 947个赞
PHP读取远程文件function urlfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype =……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2886浏览 2542个赞
php从上传的文件创建缩略图<? if ($_REQUEST['action']=="add"){ $userfile = $HTTP_POST_FILES['photo']['tmp_name']; $userfile_name = $HTTP_POST_FI……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2595浏览 173个赞
这个类可以在网上搜索,使用了Bing搜索API。它可以发送HTTP请求到Bing搜索API的Web服务器执行搜索Web内容使用以前获得的API密钥。类可以搜索网页,图片,视频,新闻和相关的关键字。<? class BingAPI{ var $accountKey = ''; var $ServiceRoo……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2745浏览 2798个赞
php获得网站访问统计信息的类Compete API,Compete是一个专门用来统计网站信息的网站<?php// Check for dependenciesif (!function_exists('curl_init')) throw new Exception('Compete needs the C……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1866浏览 866个赞
这个seo类的功能包括:– 检查指定的网站响应– 获取从该网站主页的语言和其他meta标签数据的– 获取网站的导入链接,从Alexa的流量排名– 获取网站的导入链接,由谷歌索引的网页数量– 获取网站的信任,从WOT排名。– 获取,因为它是第一个注册的网站域名年龄– 获取的Tw……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2190浏览 946个赞
在限定的区域里自动调整字体大小的php类 imagefittext.class.php<?php // Image Fit Text Class 0.1 by ming0070913 CLASS ImageFitText{ public $font, $fontsize, $width, $height; public $……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3241浏览 2010个赞
php专用数组排序的类 ArraySortUtil** * ArraySortUtil is a array sort utility, you can extends the sorting engine. * * @version 0.1 * @author coderkk Cudnik <coderkk@gmail.com&……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2932浏览 1090个赞
php封装的mongodb操作类<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class mongo_db { private $c……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2823浏览 1955个赞
php文本url转换为链接function text2links($str='') { if($str=='' or !preg_match('/(http|www\.|@)/i', $str)) { return $str; } $lines = explode(&q……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1679浏览 1936个赞
php获取来源地址function referrer_link() {$refer = $_SERVER['HTTP_REFERER']; if ($refer) { echo '<a href="' . $refer . '">Go back</a>……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2971浏览 1417个赞
php备份你的mysql数据库的代码片段<?phpbackup_tables('localhost','misslily','misslily','blog','*'); /* backup the db OR just a table ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2642浏览 2329个赞