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) 2225浏览 247个赞
php中通过定义mysql_safe_string函数防止sql注入function mysql_safe_string($value) { if(empty($value)) return 'NULL'; elseif(is_string($value)) return '\……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1469浏览 1343个赞
这段代码提供了几个常用的正则//replace all but links/<(?!\/?a(?=>|\s.*>))\/?.*?>/g //validate url/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/ //Validate……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1218浏览 2195个赞
php链接mysql的基本方法$username="username";$password="password";$database="your_database";$table="your_table"; mysql_connect(localhost,$use……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1883浏览 693个赞
面向对象的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) 1319浏览 2145个赞
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) 2811浏览 2295个赞
一个php mysql数据库操作类,功能不是很完善,但非常有用<?phpclass Database{ private $host; private $user; private $pwd; private $rows; private $error; private $result; private $dbName; pri……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2386浏览 2011个赞
这段代码比较完整,带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) 1365浏览 2004个赞
一个用来遍历CSV文件的php类<?php class CSVIterator implements Iterator{ const ROW_SIZE = 4096; private $filePointer; private $currentElement; private $rowCounter; private $del……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2708浏览 1175个赞
php发送邮件函数,支持html和普通文本<?phpfunction send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body){ $eol="\n"; $mime_boundary=md5(time()); # Commo……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1250浏览 993个赞
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) 1467浏览 1860个赞
php优化mysql数据库的所有表<?php dbConnect(); // Database connection $alltables = mysql_query("SHOW TABLES"); while ($table = mysql_fetch_assoc($alltables)) { for……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2637浏览 2344个赞
php计算到指定的日期还有多少天function countdays($d){ $olddate = substr($d, 4); $newdate = date(Y) ."".$olddate; $nextyear = date(Y)+1 ."".$olddate; if($newdate……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2591浏览 344个赞
这段php代码改变了图片直接打开为下载// The php (process.php) $file = $_GET['file'];header ("Content-type: octet/stream");header ("Content-disposition: attachment; fi……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1589浏览 1333个赞
在不破坏单词的情况下截断字符串/*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) 2036浏览 2968个赞
一个简单的php BBCode替换函数function BBcode($texto){ $a = array( "/\[i\](.*?)\[\/i\]/is", "/\[b\](.*?)\[\/b\]/is", "/\[u\](.*?)\[\/u\]/is&qu……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2647浏览 159个赞
从给定的url中移除指定的参数,如果参数不存在,则返回原urlfunction remove_querystring_var($url, $key) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1819浏览 541个赞
这段代码可以动态为url添加key-value查询参数,如果参数已经存在则会用新的进行覆盖function add_querystring_var($url, $key, $value) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&am……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1409浏览 1270个赞
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) 2031浏览 2652个赞
php验证邮件地址函数<?php function validateEmail($email){ $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2808浏览 1062个赞
php得到当前页面的完整地址function full_url(){ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $p……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3049浏览 1553个赞
一个非常全面的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) 3045浏览 539个赞
一段简单的php生成图片水印的代码,这段代码只支持图片水印function watermark($imagesource){ $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype ==……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3126浏览 2274个赞
php给自己发送自动备份的mysql数据表邮件<?// Create the mysql backup file// edit this section$dbhost = "yourhost"; // usually localhost$dbuser = "yourusername";$dbpas……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1841浏览 2421个赞
php记录Google机器人访问足迹<?php $email = "test@test.com"; if(eregi("googlebot",$HTTP_USER_AGENT)){ if ($QUERY_STRING != "") { $url ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2238浏览 2661个赞
一段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) 2128浏览 108个赞
通过这段代码可以判断用户的请求是否来自AJAX XMLHttpRequest,以区别普通post,get和ajaxfunction isAjax() {return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUES……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3629浏览 1954个赞
这段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) 1727浏览 2679个赞
一个简单的正则表达式清理不需要的字符function setDescriptionString($inputString=""){$replacedWords = array("…","‘","ó","<ul>","<li&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2959浏览 2350个赞
PHP读取远程文件function urlfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype =……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1494浏览 2286个赞
php从上传的文件创建缩略图<? if ($_REQUEST['action']=="add"){ $userfile = $HTTP_POST_FILES['photo']['tmp_name']; $userfile_name = $HTTP_POST_FI……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2386浏览 2080个赞
这个类可以在网上搜索,使用了Bing搜索API。它可以发送HTTP请求到Bing搜索API的Web服务器执行搜索Web内容使用以前获得的API密钥。类可以搜索网页,图片,视频,新闻和相关的关键字。<? class BingAPI{ var $accountKey = ''; var $ServiceRoo……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2362浏览 1116个赞
php获得网站访问统计信息的类Compete API,Compete是一个专门用来统计网站信息的网站<?php// Check for dependenciesif (!function_exists('curl_init')) throw new Exception('Compete needs the C……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2067浏览 1611个赞
这个seo类的功能包括:– 检查指定的网站响应– 获取从该网站主页的语言和其他meta标签数据的– 获取网站的导入链接,从Alexa的流量排名– 获取网站的导入链接,由谷歌索引的网页数量– 获取网站的信任,从WOT排名。– 获取,因为它是第一个注册的网站域名年龄– 获取的Tw……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2275浏览 1249个赞
在限定的区域里自动调整字体大小的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) 2806浏览 887个赞
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) 1753浏览 686个赞
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) 2443浏览 2064个赞
php文本url转换为链接function text2links($str='') { if($str=='' or !preg_match('/(http|www\.|@)/i', $str)) { return $str; } $lines = explode(&q……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1799浏览 2441个赞
php获取来源地址function referrer_link() {$refer = $_SERVER['HTTP_REFERER']; if ($refer) { echo '<a href="' . $refer . '">Go back</a>……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3742浏览 2955个赞
php备份你的mysql数据库的代码片段<?phpbackup_tables('localhost','misslily','misslily','blog','*'); /* backup the db OR just a table ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1761浏览 134个赞
一个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) 2827浏览 851个赞
把字符串中的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) 2253浏览 2167个赞
php查询数据库后,输出查询结果,隔行变色显示<?php$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name="test……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1950浏览 1863个赞
php返回文件扩展名//gets a filenames extensionfunction filename_extension($filename) {//{{{ $pos = strrpos($filename, '.'); if($pos===false) { return false; }……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3824浏览 1925个赞
一个完全面向对象的RSS/XML php类<?phperror_reporting(E_ALL); mysql_connect("localhost","root","root") or die (mysql_error());mysql_select_db("oop&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2428浏览 2986个赞