这段代码可以检测用户是否使用移动设备浏览网页,检验非常完整<?php $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolowe……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2218浏览 950个赞
这段代码简单的演示了php如何读取和分析xml文件//xml.xml : <?xml version="1.0" encoding="utf-8" ?><Kategorien> <Kategorie> <ID>1</ID> ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1189浏览 2315个赞
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]……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1508浏览 2049个赞
php中通过定义mysql_safe_string函数防止sql注入function mysql_safe_string($value) { if(empty($value)) return 'NULL'; elseif(is_string($value)) return '\……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2429浏览 2825个赞
这段代码提供了几个常用的正则//replace all but links/<(?!\/?a(?=>|\s.*>))\/?.*?>/g //validate url/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/ //Validate……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1543浏览 446个赞
php链接mysql的基本方法$username="username";$password="password";$database="your_database";$table="your_table"; mysql_connect(localhost,$use……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2924浏览 1391个赞
面向对象的mysql数据库操作php类<?phpclass database { var $host = NULL; var $username = NULL; var $password = NULL; var $databaseName = NULL; var $link = NULL; var $queries = NUL……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2983浏览 2035个赞
php获取twitter最新的消息<?phpfunction get_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_ti……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2967浏览 2651个赞
一个php mysql数据库操作类,功能不是很完善,但非常有用<?phpclass Database{ private $host; private $user; private $pwd; private $rows; private $error; private $result; private $dbName; pri……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1309浏览 1557个赞
这段代码比较完整,带session写入,mysql数据库查询//escape data and strip tagsfunction safestrip($string){ $string = strip_tags($string); $string = mysql_real_escape_string($string); return $st……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2741浏览 2245个赞
一个用来遍历CSV文件的php类<?php class CSVIterator implements Iterator{ const ROW_SIZE = 4096; private $filePointer; private $currentElement; private $rowCounter; private $del……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2486浏览 421个赞
php发送邮件函数,支持html和普通文本<?phpfunction send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body){ $eol="\n"; $mime_boundary=md5(time()); # Commo……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2988浏览 731个赞
php返回相对时间,如:20分钟前,3天前function plural($num) { if ($num != 1) return "s";} function getRelativeTime($date) { $diff = time() - strtotime($date); if ($diff<60)……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3074浏览 2786个赞
php优化mysql数据库的所有表<?php dbConnect(); // Database connection $alltables = mysql_query("SHOW TABLES"); while ($table = mysql_fetch_assoc($alltables)) { for……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1361浏览 889个赞
php计算到指定的日期还有多少天function countdays($d){ $olddate = substr($d, 4); $newdate = date(Y) ."".$olddate; $nextyear = date(Y)+1 ."".$olddate; if($newdate……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2863浏览 1865个赞
这段php代码改变了图片直接打开为下载// The php (process.php) $file = $_GET['file'];header ("Content-type: octet/stream");header ("Content-disposition: attachment; fi……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2466浏览 711个赞
在不破坏单词的情况下截断字符串/*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……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1608浏览 476个赞
一个简单的php BBCode替换函数function BBcode($texto){ $a = array( "/\[i\](.*?)\[\/i\]/is", "/\[b\](.*?)\[\/b\]/is", "/\[u\](.*?)\[\/u\]/is&qu……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2831浏览 504个赞
从给定的url中移除指定的参数,如果参数不存在,则返回原urlfunction remove_querystring_var($url, $key) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1570浏览 1970个赞
这段代码可以动态为url添加key-value查询参数,如果参数已经存在则会用新的进行覆盖function add_querystring_var($url, $key, $value) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&am……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2699浏览 167个赞
php修改上传图片的尺寸<?php // This is the temporary file created by PHP$uploadedfile = $_FILES['uploadfile']['tmp_name']; // Create an Image from it so we can……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3033浏览 2869个赞
php验证邮件地址函数<?php function validateEmail($email){ $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1219浏览 2392个赞
php得到当前页面的完整地址function full_url(){ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $p……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2127浏览 2012个赞
一个非常全面的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}@[^@]……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1839浏览 2630个赞
一段简单的php生成图片水印的代码,这段代码只支持图片水印function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype ==……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1310浏览 2027个赞
php给自己发送自动备份的mysql数据表邮件<?// Create the mysql backup file// edit this section$dbhost = "yourhost"; // usually localhost$dbuser = "yourusername";$dbpas……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2461浏览 2011个赞
php记录Google机器人访问足迹<?php $email = "test@test.com"; if(eregi("googlebot",$HTTP_USER_AGENT)){ if ($QUERY_STRING != "") { $url ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1296浏览 1738个赞
一段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……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1382浏览 1211个赞
通过这段代码可以判断用户的请求是否来自AJAX XMLHttpRequest,以区别普通post,get和ajaxfunction isAjax() {return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUES……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2637浏览 2702个赞
这段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. *……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1982浏览 2622个赞
一个简单的正则表达式清理不需要的字符function setDescriptionString($inputString=""){$replacedWords = array("…","‘","ó","<ul>","<li&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2752浏览 1280个赞
PHP读取远程文件function urlfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype =……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2067浏览 1653个赞
php从上传的文件创建缩略图<? if ($_REQUEST['action']=="add"){ $userfile = $HTTP_POST_FILES['photo']['tmp_name']; $userfile_name = $HTTP_POST_FI……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2686浏览 2942个赞
这个类可以在网上搜索,使用了Bing搜索API。它可以发送HTTP请求到Bing搜索API的Web服务器执行搜索Web内容使用以前获得的API密钥。类可以搜索网页,图片,视频,新闻和相关的关键字。<? class BingAPI{ var $accountKey = ''; var $ServiceRoo……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2101浏览 802个赞
php获得网站访问统计信息的类Compete API,Compete是一个专门用来统计网站信息的网站<?php// Check for dependenciesif (!function_exists('curl_init')) throw new Exception('Compete needs the C……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2120浏览 2551个赞
这个seo类的功能包括:– 检查指定的网站响应– 获取从该网站主页的语言和其他meta标签数据的– 获取网站的导入链接,从Alexa的流量排名– 获取网站的导入链接,由谷歌索引的网页数量– 获取网站的信任,从WOT排名。– 获取,因为它是第一个注册的网站域名年龄– 获取的Tw……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2383浏览 766个赞
在限定的区域里自动调整字体大小的php类 imagefittext.class.php<?php // Image Fit Text Class 0.1 by ming0070913 CLASS ImageFitText{ public $font, $fontsize, $width, $height; public $……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2237浏览 1725个赞
php专用数组排序的类 ArraySortUtil** * ArraySortUtil is a array sort utility, you can extends the sorting engine. * * @version 0.1 * @author coderkk Cudnik <coderkk@gmail.com&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2270浏览 422个赞
php封装的mongodb操作类<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class mongo_db { private $c……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2103浏览 489个赞
php文本url转换为链接function text2links($str='') { if($str=='' or !preg_match('/(http|www\.|@)/i', $str)) { return $str; } $lines = explode(&q……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1452浏览 489个赞
php获取来源地址function referrer_link() {$refer = $_SERVER['HTTP_REFERER']; if ($refer) { echo '<a href="' . $refer . '">Go back</a>……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3389浏览 603个赞
php备份你的mysql数据库的代码片段<?phpbackup_tables('localhost','misslily','misslily','blog','*'); /* backup the db OR just a table ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2189浏览 949个赞
一个php表单验证的演示代码,如果验证失败会在当前页显示提示信息<?php // Quick function to loop through regexs and compare to what is in _POST// // $regs -> associative array of regular exp……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1296浏览 2954个赞
把字符串中的url替换成可点击的链接,默认给链接添加nofollow,即不允许搜索引擎搜索function replace_urls($string, $rel = 'nofollow'){ $host = "([a-z\d][-a-z\d]*[a-z\d]\.)+[a-z][-a-z\d]*[a-z]"……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2880浏览 824个赞
php查询数据库后,输出查询结果,隔行变色显示<?php$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name="test……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2994浏览 953个赞