function.inc.php超越php
发布时间:2024-06-05 09:22:40
<?php
/**
* Global Function
*
* @author Avenger <avenger@php.net>
* @version 1.14 $Id 2003-05-30 10:10:08 $
*/
/**
* 弹出提示框
*
* @access public
* @param string $txt 弹出一个提示框,$txt为要弹出的内容
* @return void
*/
function popbox($txt) {
echo "<script language='JavaScript'>alert('".$txt."')</script>";
}
/**
* 非法操作警告
*
* @access public
* @param string $C_alert 提示的错误信息
* @param string $I_goback 返回后返回到哪一页,不指定则不返回
* @return void
*/
function alert($C_alert,$I_goback='main.php') {
if(!empty($I_goback)) {
echo "<script>alert('$C_alert');window.location.href='$I_goback';</script>";
} else {
echo "<script>alert('$C_alert');</script>";
}
}
/**
* 产生随机字符串
*
* 产生一个指定长度的随机字符串,并返回给用户
*
* @access public
* @param int $len 产生字符串的位数
* @return string
*/
function randstr($len=6) {
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'; // characters to build the password from
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
/**
* 判断下拉菜音的选取项
*
* 可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择
*
* @access public
* @param string $str1 要比较的字符串一
* @param string $str2 要比较的字符串二
* @return string 相等返回字符串"selected",否则返回空字符串
*/
function ckselect($str1,$str2) {
if($str1==$str2) {
return ' selected';
}
return '';
}
/**
* 一个自定义的Ftp函数
*
* @access private
* @return void
*/
function myftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/') {
$ftpid=@ftp_connect($ftp_server,$ftp_port) or die('Connect To Ftp Server Error!');
@ftp_login($ftpid,$ftp_username,$ftp_password) or die('Login Ftp Error!');
@ftp_chdir($ftpid,'/'.$ftp_path) or die('Chdir Error!');
return $ftpid;
}
/**
* 截取中文部分字符串
*
* 截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码
*
* @access public
* @param string $str 要处理的字符串
* @param int $strlen 要截取的长度默认为10
* @param string $other 是否要加上省略号,默认会加上
* @return string
*/
function showtitle($str,$strlen=10,$other=true) {
$j = 0;
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$rstr=substr($str,0,$strlen);
if (strlen($str)>$strlen && $other) {$rstr.='...';}
return $rstr;
}
/**
* 制作链接
*
* @access public
* @param string url 要链接到的网址
* @param string linktext 显示的链接文字
* @param string target 目标框架
* @param string extras 扩展参数
* @return string
*/
function make_link ($url, $linktext=false, $target=false, $extras=false) {
return sprintf("<a href=\"%s\"%s%s>%s</a>",
$url,
($target ? ' target="'.$target.'"' : ''),
($extras ? ' '.$extras : ''),
($linktext ? $linktext : $url)
);
}
/**
* 格式化用户评论
*
* @access public
* @param string
* @return void
*/
function clean_note($text) {
$text = htmlspecialchars(trim($text));
/* turn urls into links */
$text = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<a href=\"\1\">\1</a>\3",$text);
/* this 'fixing' code will go away eventually. */
$fixes = array('<br>', '<p>', '</p>');
reset($fixes);
while (list(,$f) = each($fixes)) {
$text = str_replace(htmlspecialchars($f), $f, $text);
$text = str_replace(htmlspecialchars(strtoupper($f)), $f, $text);
}
/* <p> tags make things look awfully weird (breaks things out of the <code>
tag). Just convert them to <br>'s
*/
$text = str_replace (array ('<P>', '<p>'), '<br>', $text);
/* Remove </p> tags to prevent it from showing up in the note */
$text = str_replace (array ('</P>', '</p>'), '', $text);
/* preserve linebreaks */
$text = str_replace("\n", "<br>", $text);
/* this will only break long lines */
if (function_exists("wordwrap")) {
$text = wordwrap($text);
}
// Preserve spacing of user notes
$text = str_replace(" ", " ", $text);
return $text;
}
/**
* 获取图象信息的函数
*
* 一个全面获取图象信息的函数
*
* @access public
* @param string $img 图片路径
* @return array
*/
function getimageinfo($img) {
$img_info = getimagesize($img);
switch ($img_info[2]) {
case 1:
$imgtype = "GIF";
break;
case 2:
$imgtype = "JPG";
break;
case 3:
$imgtype = "PNG";
break;
}
$img_size = ceil(filesize($img)/1000)."k";
$new_img_info = array (
"width"=>$img_info[0],
"height"=>$img_info[1],
"type"=>$imgtype,
"size"=>$img_size
);
return $new_img_info;
}
/**
* 计算当前时间
*
* 以微秒为单位返回当前系统的时间
*
* @access public
* @return real
*/
function getmicrotime() {
$tmp = explode(' ', microtime());
return (real)$tmp[1]. substr($tmp[0], 1);
}
/**
* 写文件操作
*
* @access public
* @param bool
* @return void
*/
function wfile($file,$content,$mode='w') {
$oldmask = umask(0);
$fp = fopen($file, $mode);
if (!$fp) return false;
fwrite($fp,$content);
fclose($fp);
umask($oldmask);
return true;
}
/**
* 加载模板文件
*
* @access public
* @return void
*/
function tpl_load($tplfile,$path='./templates/',$empty='remove') {
global $tpl;
$path ? '' : $path='./templates/';
require_once 'HTML/Template/PHPLIB.php';
$tpl = new Template_PHPLIB($path,$empty);
$tpl->setFile('main',$tplfile);
}
/**
* 模板解析输出
*
* @access public
* @return void
*/
function tpl_output() {
global $tpl;
$tpl->parse('output','main');
$tpl->p('output');
}
/**
* 邮件发送函数
*
* @access public private
* @param bool
* @return void
*/
function mailSender($from, $to, $title, $content) {
$from ? $from = 'sender@phpe.net' : '';
$title ? $title = 'From Exceed PHP...' : '';
$sig = "
感谢您使用我们的服务.\n\n
Exceed PHP(超越PHP)\n
$maildate\n\n
---------------------------------------------------------------------------------------
\n\n
去发现极限方法的唯一办法就是去超越它\n
超越PHP欢迎您(http://www.phpe.net)\n
";
$content .= $sig;
if (@mail($to, $title, $content, "From:$from\nReply-To:$from")) {
return true;
} else {
return false;
}
}
function br2none($str) {
return str_replace(array('<br>', '<br />'), "", $str);
}
/**
* UBB解析
*
* @param none
* @access public
* @return void
*/
function ubbParse($txt, $coverhtml=0) {
if ($coverhtml == 0) $txt = nl2br(new_htmlspecialchars($txt)); //BR和HTML转换
//只转换BR,不转换HTML
if ($coverhtml == 1) {
if (!preg_match('/<\s*(p|br)\s*>/is', $txt) && !preg_match('/<table.+<\/table>/is', $txt)) {
$txt = strip_tags($txt);
$txt = nl2br($txt);
} else {
$txt = str_replace('<?', '<?', $txt);
}
}
// pre and quote
//error_reporting(E_ALL);
$txt = preg_replace( "#\[quote\](.+?)\[/quote\]#is", "<blockquote>\1</blockquote>", $txt );
$txt = preg_replace( "#\[code\](.+?)\[/code\]#ise", "'<pre class=php>'.br2none('').'</pre>'", $txt );
// Colors 支持篏套
while( preg_match( "#\[color=([^\]]+)\](.+?)\[/color\]#is", $txt ) ) {
$txt = preg_replace( "#\[color=([^\]]+)\](.+?)\[/color\]#is", "<span style='color:\1'>\2</span>", $txt );
}
// Align
$txt = preg_replace( "#\[center\](.+?)\[/center\]#is", "<center>\1</center>", $txt );
$txt = preg_replace( "#\[left\](.+?)\[/left\]#is", "<div align=left>\1</div>", $txt );
$txt = preg_replace( "#\[right\](.+?)\[/right\]#is", "<div align=right>\1</div>", $txt );
// Sub & sup
$txt = preg_replace( "#\[sup\](.+?)\[/sup\]#is", "<sup>\1</sup>", $txt );
$txt = preg_replace( "#\[sub\](.+?)\[/sub\]#is", "<sub>\1</sub>", $txt );
// email tags
// [email]avenger@php.net[/email] [email=avenger@php.net]Email me[/email]
$txt = preg_replace( "#\[email\](\S+?)\[/email\]#i" , "<a href='mailto:\1'>\1</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\1'>\2</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\1'>\2</a>", $txt );
// url tags
// [url]http://www.phpe.net[/url] [url=http://www.phpe.net]Exceed PHP![/url]
$txt = preg_replace( "#\[url\](\S+?)\[/url\]#i" , "<a href='\1' target='_blank'>\1</a>", $txt );
$txt = preg_replace( "#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i" , "<a href='\1' target='_blank'>\2</a>", $txt );
$txt = preg_replace( "#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i" , "<a href='\1' target='_blank'>\2</a>", $txt );
// Start off with the easy stuff
$txt = preg_replace( "#\[b\](.+?)\[/b\]#is", "<b>\1</b>", $txt );
$txt = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>\1</i>", $txt );
$txt = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>\1</u>", $txt );
$txt = preg_replace( "#\[s\](.+?)\[/s\]#is", "<s>\1</s>", $txt );
// Header text
$txt = preg_replace( "#\[h([1-6])\](.+?)\[/h[1-6]\]#is", "<h\1>\2</h\1>", $txt );
// Images
$txt = preg_replace( "#\[img\](.+?)\[/img\]#i", "<a href='\1' target='_blank'><img alt='Click to fullsize' src='\1' border='0' onload='javascript:if(this.width>500) this.width=500' align='center' hspace='10' vspace='10'></a><br />", $txt );
// Attach
$txt = preg_replace( "#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i" , "<a href='\2' target='_blank'><b>相关附件:</b>\1</a>", $txt );
$txt = preg_replace( "#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i" , "<a href='\2' target='_blank'><b>相关附件:</b>\1</a>", $txt );
// Iframe
$txt = preg_replace( "#\[iframe\](.+?)\[/iframe\]#i", "<div align='center'><iframe src='\1' style='width:96%;height:400px'></iframe><br clear='all'><a href='\1' target='_blank'>在新窗口打开链接</a></div>", $txt );
// (c) (r) and (tm)
$txt = preg_replace( "#\(c\)#i" , "©" , $txt );
$txt = preg_replace( "#\(tm\)#i" , "™" , $txt );
$txt = preg_replace( "#\(r\)#i" , "®" , $txt );
return $txt;
}
//重新格式化日期
function format_date($date) {
if (!preg_match('/^\d+$/', $date)) $date = strtotime(trim($date));
$sec = time() - $date;
//Sec 1 day is 86400
if ($sec < 86400) {
return round($sec/3600). ' hours ago';
} elseif ($sec < (86400 * 7)) {
return round($sec/86400). ' days ago';
} elseif ($sec < (86400 * 7 * 4)) {
return round($sec/(86400*7)). ' weeks ago';
} else {
return date('Y-m-d', $date);
}
}
?>
猜你喜欢
- 今天将webserice里面的一个代码,拷到一个C#类,结果运行编译错误。DataBase = Server.MapPath("d
- 为了庆祝jQuery的四周岁生日, jQuery的团队荣幸的发布了jQuery Javascript库的最新主要版本! 这个版本包含了大量的
- 一、前言最近做web网站的测试,遇到很多需要批量造数据的功能;比如某个页面展示数据条数需要达到10000条进行测试,此时手动构造数据肯定是不
- 邮件自动化篇章所需的新模块:smtplib 邮件协议与发送模块email 内容定义模块schedule 定时模块smtplib 与 emai
- 项目需要在electron的项目中新打开一个窗口,利用webpack作为静态资源打包器,发现在webpack中可以设置多页面的入口,今天来讲
- 前言本文主要给大家介绍关于python中__init__、__new__和__call__方法的相关内容,分享出来供大家参考学习,下面话不多
- 1.获取远程包go 语言有一个获取远程包的工具就是 go get,目前 go get 支持多数开源社区 (例如:github、googlec
- 本文实例讲述了RC4文件加密的python实现方法。分享给大家供大家参考。具体分析如下:基于RC4流加密算法,使用扩展的16*16的S盒,3
- PDF是我们经常会接触到的一种文件格式,文献、文档...很多都是PDF格式。它以格式稳定的优势,使得我们在打印、分享、传输过程中能够最优的保
- 一、 腐蚀与膨胀1.1 腐蚀操作import cv2import numpy as npimg = cv2.imread('Data
- 1. 场景大家好,我是J哥。前段时间有人私信我,说自己辛辛苦苦剪辑的短视频,上传到某平台后,由于播放量太大,收到 降权 的通知,直接导致这个
- 按下"开始(win)"按钮和R键,输入cmd,打开命令行寻找点击需要的库:https://www.lfd.uci.edu
- 效果演示基础源码1.基础设置(tools部分)这个部分设置马里奥以及游戏中蘑菇等怪的的移动设置。import osimport pygame
- 曾经有许多创造性的logo设计案例,logo设计资源和logo设计指导张贴在互联网的各个角落。这些帮助会为你的logo设计创造一个功能强大的
- 今天分享的这篇文章,文字不多,代码为主。绝对干货,童叟无欺,主要分享了提升 Python 性能的 20 个技巧,教你如何告别慢Python。
- 本文所依赖的环境为:进程和线程的概念进程概念我们想运行一个程序,首先会将该程序从存储介质上通过IO总线加载进内存中,而后再通过cpu进行调度
- 目的:JS+ASP打造无刷新新闻列表,下图所示的新闻列表相信大家并不少见,包括新闻的分页功能,本文要介绍的就是各分页间的切换方式。传统的方法
- 这段时间服务器崩溃2次,一直没有找到原因,今天看到论坛发出的错误信息邮件,想起可能是MySQL的默认连接数引起的问题,一查果然,老天,默认
- 一、特效预览处理前处理后细节放大后二、程序原理1.将图片转为灰白图片后,将图片分成了三块,明、暗、阴影区域2.明区域使用空白进行填充3.阴影
- 最近要做一个图像生成的课题,在网上找了一个混合的数据集。这个数据集中一共有360个文件夹,然后文件夹中有6-9张不等的照片,我的目标就是编写