function.inc.php³¬Ô½php

5年以前  |  阅读数:962 次  |  编程语言:PHP 

<?php
/**

  • Global Function
  • @author Avenger avenger@php.net
  • @version 1.14 $Id 2003-05-30 10:10:08 $
    */
    /**
  • µ¯³oÌaʾ¿o
  • @access public
  • @param string $txt µ¯³oÒ»¸oÌaʾ¿o£¬$txtΪҪµ¯³oµÄÄÚÈÝ
  • @return void
    */
    function popbox($txt) {
    echo "";
    }
    /**
  • Ǩ²Ù×÷¾¯¸ae
  • @access public
  • @param string $C_alert ÌaʾµÄ´iÎoÐÅÏ¢
  • @param string $I_goback µ»Øºoµ»Øµ½ÄÄÒ»Ò³,²»Ö¸¶¨Ôo²»*µ»Ø
  • @return void
    */
    function alert($C_alert,$I_goback='main.php') {
    if(!empty($I_goback)) {
    echo "";
    } else {
    echo "";
    }
    }
    /**
  • ²uÉuËae»u×Ö*u´®
  • ²uÉuÒ»¸oÖ¸¶¨³¤¶ÈµÄËae»u×Öu´®,²¢µ»Ø¸øÓû§
  • @access public
  • @param int $len ²uÉu×Ö*u´®µÄλÊý
  • @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;
    }
    /**
  • ÅжÏÏÂÀ­²ËÒoµÄÑ¡È¡Ïi
  • ¿ÉÒÔÅжÏ×Öu´®Ò»ºÍ×Öu´®¶þÊÇ*ñÏaµÈ.´Ó¶øʹÏaµÈµÄÏiÄ¿ÔÚÏÂÀ­²Ëµ¥Öб»Ñ¡Ôñ
  • @access public
  • @param string $str1 Òª±È½ÏµÄ×Ö*u´®Ò»
  • @param string $str2 Òª±È½ÏµÄ×Ö*u´®¶þ
  • @return string ÏaµÈµ»Ø×Öu´®"selected",ñÔoµ»Ø¿Õ×Öu´®
    /
    function ckselect($str1,$str2) {
    if($str1==$str2) {
    return ' selected';
    }
    return '';
    }
    /**
  • Ò»¸o×Ô¶¨ÒaµÄ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;
    }
    /**
  • ½ØÈ¡ÖÐÎIJ¿Ö×Öu´®
  • ½ØÈ¡Ö¸¶¨×Ö*u´®Ö¸¶¨³¤¶ÈµÄº¯Êý,¸Ãº¯Êý¿É×Ô¶¯Åж¨ÖÐÓ¢ÎÄ,²»»a³oÏÖÂÒÂe
  • @access public
  • @param string $str Òª´¦ÀiµÄ×Ö*u´®
  • @param int $strlen Òª½ØÈ¡µÄ³¤¶ÈĬÈÏΪ10
  • @param string $other ÊÇ*ñÒª¼ÓÉÏÊ¡ÂÔºÅ,ĬÈÏ»a¼ÓÉÏ
  • @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 Ä¿±e¿o¼Ü
  • @param string extras À(C)Õ¹²ÎÊý
  • @return string
    */
    function make_link ($url, $linktext=false, $target=false, $extras=false) {
    return sprintf("<a href=\"%s\"%s%s>%s",
    $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\3",$text);
    /
    this 'fixing' code will go away eventually. /
    $fixes = array('
    ', '

    ', '

    ');
    reset($fixes);
    while (list(,$f) = each($fixes)) {
    $text = str_replace(htmlspecialchars($f), $f, $text);
    $text = str_replace(htmlspecialchars(strtoupper($f)), $f, $text);
    }
    /

    tags make things look awfully weird (breaks things out of the
    tag). Just convert them to
    's
    /
    $text = str_replace (array ('

    ', '

    '), '
    ', $text);
    /
    Remove

    tags to prevent it from showing up in the note /
    $text = str_replace (array ('

    ', '

    '), '', $text);
    /
    preserve linebreaks /
    $text = str_replace("\n", "
    ", $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;
    }
    /**
  • »ñȡͼÏoÐÅÏ¢µÄº¯Êý
  • Ò»¸oÈ«Ãae»ñȡͼÏoÐÅÏ¢µÄº¯Êý
  • @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;
    }
    /**
  • ¼ÆËaµ±Ç°Ê±¼a
  • ÒÔ΢ÃeΪµ¥Î»*µ»Øµ±Ç°ÏµÍ³µÄʱ¼a
  • @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;
    }
    /**
  • ¼ÓÔØÄ£°aÎļþ
  • @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);
    }
    /**
  • Ä£°a½aÎoÊa³o
  • @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 = "
    ¸ÐлÄuʹÓÃÎÒÃǵÄ
    þÎñ.\n\n
    Exceed PHP(³¬Ô½PHP)\n
    $maildate\n\n
    ---------------------------------------------------------------------------------------
    \n\n
    È¥¢ÏÖ¼«ÏÞ½¨µÄΨһ°i¨¾ÍÊÇÈ¥³¬Ô½Ëu\n
    ³¬Ô½PHP»¶Ó­Äu(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('
    ', '
    '), "", $str);
    }
    /**
  • UBB½aÎo
  • @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", "
    \1
    ", $txt );
    $txt = preg_replace( "#\code\\[/code\]#ise", "'
    '.br2none('').'
    '", $txt );
    // Colors Ö§³ÖºGÌ×
    while( preg_match( "#\[color=([^\]]+)\](.+?)\[/color\]#is", $txt ) ) {
    $txt = preg_replace( "#\[color=([^\]]+)\](.+?)\[/color\]#is", "\2", $txt );
    }
    // Align
    $txt = preg_replace( "#\center\\[/center\]#is", "
    \1
    ", $txt );
    $txt = preg_replace( "#\left\\[/left\]#is", "
    \1
    ", $txt );
    $txt = preg_replace( "#\right\\[/right\]#is", "
    \1
    ", $txt );
    // Sub & sup
    $txt = preg_replace( "#\sup\\[/sup\]#is", "\1", $txt );
    $txt = preg_replace( "#\sub\\[/sub\]#is", "\1", $txt );
    // email tags
    // [email]avenger@php.net[/email] [email=avenger@php.net]Email me[/email]
    $txt = preg_replace( "#\email\\[/email\]#i" , "\1", $txt );
    $txt = preg_replace( "#\[email\s
    =\s\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s\"\;\s\](.?)\[\/email\]#i" , "\2", $txt );
    $txt = preg_replace( "#\email\s=\s([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\\[\/email\]#i" , "\2", $txt );
    // url tags
    // [url]http://www.phpe.net[/url] [url=http://www.phpe.net]Exceed PHP![/url]
    $txt = preg_replace( "#\url\\[/url\]#i" , "\1", $txt );
    $txt = preg_replace( "#\url\s=\s\"\;\s(\S+?)\s\"\;\s*\\[\/url\]#i" , "\2", $txt );
    $txt = preg_replace( "#\url\s=\s(\S+?)\s*\\[\/url\]#i" , "\2", $txt );
    // Start off with the easy stuff
    $txt = preg_replace( "#\b\\[/b\]#is", "\1", $txt );
    $txt = preg_replace( "#\i\\[/i\]#is", "\1", $txt );
    $txt = preg_replace( "#\u\\[/u\]#is", "\1", $txt );
    $txt = preg_replace( "#\s\\[/s\]#is", "\1", $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", "Click to fullsize
    ", $txt );
    // Attach
    $txt = preg_replace( "#\attach\s=\s\"\;\s(\S+?)\s\"\;\s*\\[\/attach\]#i" , "Ïa¹Ø¸½¼þ£º\1", $txt );
    $txt = preg_replace( "#\attach\s=\s(\S+?)\s*\\[\/attach\]#i" , "Ïa¹Ø¸½¼þ£º\1", $txt );
    // Iframe
    $txt = preg_replace( "#\iframe\\[/iframe\]#i", "", $txt );
    // (c) (r) and (tm)
    $txt = preg_replace( "#\(c\)#i" , "(C)" , $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);
    }
    }
    ?>
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例