ホームページ  >  記事  >  バックエンド開発  >  function.inc.phpbeyondphp_PHP チュートリアル

function.inc.phpbeyondphp_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:59:01771ブラウズ

/**
* グローバル関数
*
* @author Avenger
* @version 1.14 $Id 2003-05-30 10:10:08 $
 */
/**
* プロンプトボックスをポップアップします
*
* @access public
* @param string $txt プロンプトボックスをポップアップします、$txt はポップアップされる内容です
* @return void
*/
function popbox($txt) {
echo "";
}
/**
* 不正操作警告
*
* @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-@#~'; //
mt_srand((double)microtime()*1000000*getmypid()); からパスワードを構築するための文字 // 乱数ジェネレータのシード(必ず実行する必要があります)
$password='';
while(strlen($password) $password.=substr($chars,(mt_rand()%strlen($chars)),1);
$password を返す;
}
/**
* ドロップダウン メニューの選択された項目を決定します
*
* 文字列 1 と文字列 2 が等しいかどうかを決定して、等しい項目がドロップダウン メニューで選択されるようにします
*
* @access public
* @param string $str1 比較される文字列 1
* @param string $str2 比較される文字列 2
* @return string 等しい場合は文字列「selected」を返し、それ以外の場合は空の文字列を返します
*/
function ckselect($str1,$str2) {
if($str1==$str2) {
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) さもなければ死ぬ(「FTP サーバーへの接続エラー!」);
@ftp_login($ftpid,$ftp_username,$ftp_password) or die('ログイン FTP エラー!');
@ftp_chdir($ftpid,'/'.$ftp_path) または die('Chdir Error!');
$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 リンク先の URL
* @param string linktext 表示されるリンクテキスト
* @param string ターゲットフレームワーク
* @param string 追加の拡張パラメータ
* @return文字列
*/
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));
/* URL をリンクに変換 */
$text = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|s|)|"|.s|$)/ ","13",$text);
/*この「修正」コードは最終的には廃止されます。*/
$fixes = array('','

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

タグは非常に奇妙に見えます タグの内容を分割します)。それらを

*/
$text = str_replace (array ('

',

'), '
', $text);
/* メモに表示されないように

タグを削除します */
$text = str_replace (array ('

','< /p>'), '', $text);
/* 改行を維持 */
$text = str_replace("n", "
", $text); これにより、長い行のみが改行されます。 */
if (function_exists("wordwrap")) {
$text = wordwrap($text);
}
// ユーザーメモの間隔を保持します
$text = str_replace(" ", " ", $text);
$text を返す;
}
/**
* 画像情報を取得する関数
*
* 画像情報を網羅的に取得する関数
*
* @access public
* @param string $img 画像パス
* @return array
*/
function getimageinfo($img) {
$img_info = getimagesize($img);
switch ($img_info[2]) {
case 1:
$imgtype = "GIF";
休憩;
ケース 2:
$imgtype = "JPG";
休憩;
ケース 3:
$imgtype = "PNG";
休憩;
}
$img_size = ceil(filesize($img)/1000)."k";
$new_img_info = array (
"width"=>$img_info[0],
"height"=>$img_info[1],
"type"=>$imgtype,
"サイズ"=>$ img_size
);
$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);
true を返します。
}
/**
* テンプレートファイルをロード
*
* @access public
* @return void
*/
function tpl_load($tplfile,$path='./templates/',$empty='remove') {
global $tpl;
$パス ? '' : $path='./templates/'; 
require_once 'HTML/テンプレート/PHPLIB.php';
$tpl = 新しい 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('/<\s*(p|br)\s*>/is', $txt) && !preg_match('//is', $txt)) {
            $txt = strip_tags($txt);
            $txt = nl2br($txt);
        } else {
            $txt = str_replace(' }
}
// 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", $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" , "相关附件:\1", $txt );
    $txt = preg_replace( "#[attachs*=s*(S+?)s*](.*?)[/attach]#i" , "< ;b>関連添付ファイル:1", $txt );
// iframe
$txt = preg_replace( "#[iframe](.+?)[/iframe]#i", "

在新窗口打开链接",$txt );
// (c) (r) および (tm)
$txt = preg_replace( "#(c)#i" , "©" , $txt );
$txt = preg_replace( "#(tm)#i" , "" , $txt );
$txt = preg_replace( "#(r)#i" , "®" , $txt );
$txt を返す;
}
//重新格式化日期
function format_date($date) {
if (!preg_match('/^d+$/', $date)) $date = strtotime(trim($date));
$sec = time() - $date;
//Sec 1 day は 86400
if ($sec return round($sec/3600)。 ' 時間前';
} elseif ($sec < (86400 * 7)) {
return round($sec/86400)。 ' 数日前';
} elseif ($sec < (86400 * 7 * 4)) {
return round($sec/(86400*7))。 ' 何週間前';
} else {
return date('Y-m-d', $date);
}
}
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/317462.html技術記事 ?php /***GlobalFunction * *@authorAvengeravenger@php.net *@version1.14$Id2003-05-3010:10:08$*/ /** *弹出提案框 * *@accesspublic *@paramstring$txt弹出一提案框,$txtは...