찾다
백엔드 개발PHP 튜토리얼function.inc.php超越php_PHP教程

/**
 * Global Function
 *
 * @author   Avenger 
 * @version 1.14 $Id 2003-05-30 10:10:08 $
 */
/**
 * 弹出提示框
 *
 * @access public
 * @param string $txt 弹出一个提示框,$txt为要弹出的内容
 * @return void
 */
function popbox($txt) {
    echo "<script>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)        $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      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("%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|$)/","\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  <br>       tag). Just convert them to <br>'s <br>    */ <br>    $text = str_replace (array ('<p>', '</p> <p>'), '<br>', $text); <br>    /* Remove </p> tags to prevent it from showing up in the note */ <br>    $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;
}
/**
 * 获取图象信息的函数
 *
 * 一个全面获取图象信息的函数
 *
 * @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('
', '
'), "", $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('//is', $txt) && !preg_match('//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 支持篏套
    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\](\S+?)\[/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\](\S+?)\[/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", "\2\1>", $txt );
    // Images
    $txt = preg_replace( "#\[img\](.+?)\[/img\]#i", "function.inc.php超越php_PHP教程500) this.width=500' align='center' hspace='10' vspace='10'>
", $txt );
    // Attach
    $txt = preg_replace( "#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i" , "相关附件:\1", $txt );
    $txt = preg_replace( "#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i"                       , "相关附件:\1", $txt );
    // Iframe
    $txt = preg_replace( "#\[iframe\](.+?)\[/iframe\]#i", "

在新窗口打开链接
", $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         return round($sec/3600). ' hours ago';
    } elseif ($sec         return round($sec/86400). ' days ago';
    } elseif ($sec         return round($sec/(86400*7)). ' weeks ago';
    } else {
        return date('Y-m-d', $date);
    }
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317462.htmlTechArticle?php /** *GlobalFunction * *@authorAvengeravenger@php.net *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为...
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.