Function. inc. php surpasses php

Source: Internet
Author: User

<? Php
/**
* Global Function
*
* @ Author Avenger <avenger@php.net>
* @ Version 1.14 $ Id 10:10:08 $
*/
/**
* A prompt box is displayed.
*
* @ Access public
* @ Param string $ txt a prompt box is displayed. $ txt indicates the content to be displayed.
* @ Return void
*/
Function popbox ($ txt ){
Echo "<script language = 'javascript '> alert ('". $ txt. "') </script> ";
}
/**
* Invalid operation warning
*
* @ Access public
* @ Param string $ C_alert error message
* @ Param string $ I _goback: the page to which the system returns the result. If this parameter is not specified, the system does not return the result.
* @ 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> ";
}
}
/**
* Generate random strings
*
* Generates a random string of the specified length and returns it to the user.
*
* @ Access public
* @ Param int $ len: number of digits of the string generated
* @ 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;
}
/**
* Determine the selection items of the drop-down menu.
*
* You can determine whether the two strings are equal, so that the items that are equal can be selected from the drop-down list.
*
* @ Access public
* @ Param string $ str1 string to be compared
* @ Param string $ str2 string 2 to be compared
* @ Return string equal return string "selected"; otherwise return an empty string
*/
Function ckselect ($ str1, $ str2 ){
If ($ str1 = $ str2 ){
Return 'selected ';
}
Return '';
}
/**
* A custom Ftp Function
*
* @ 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;
}
/**
* Truncates some Chinese strings.
*
* Truncates a function with the specified length of a specified string. This function can automatically determine Chinese and English characters without garbled characters.
*
* @ Access public
* @ Param string $ str the string to be processed
* @ Param int $ strlen the default length to be intercepted is 10.
* @ Param string $ specifies whether to add a ellipsis to other. By default
* @ 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;
}
/**
* Create a link
*
* @ Access public
* @ Param string url the url to be linked
* @ Param string the link text displayed by linktext
* @ Param string target framework
* @ Param string extras extension Parameters
* @ Return string
*/
Function make_link ($ url, $ linktext = false, $ target = false, $ extras = false ){
Return sprintf ("<a href = \" % s \ "% s> % s </a> ",
$ Url,
($ Target? 'Target = "'. $ target .'"':''),
($ Extras? ''. $ Extras :''),
($ Linktext? $ Linktext: $ url)
);
}
/**
* Format user comments
*
* @ 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;
}
/**
* Function for retrieving Image Information
*
* A function that comprehensively obtains image information
*
* @ Access public
* @ Param string $ img image path
* @ 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;
}
/**
* Calculate the current time
*
* Returns the current system time in microseconds.
*
* @ Access public
* @ Return real
*/
Function getmicrotime (){
$ Tmp = explode ('', microtime ());
Return (real) $ tmp [1]. substr ($ tmp [0], 1 );
}
/**
* File write operations
*
* @ 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;
}
/**
* Load the Template File
*
* @ Access public
* @ Return void
*/
Function tpl_load ($ tplfile, $ path = './templates/', $ empty = 'delete '){
Global $ tpl;
$ Path? '': $ Path = './templates /';
Require_once 'html/Template/PHPLIB. php ';
$ Tpl = new Template_PHPLIB ($ path, $ empty );
$ Tpl-> setFile ('main', $ tplfile );
}
/**
* Template parsing output
*
* @ Access public
* @ Return void
*/
Function tpl_output (){
Global $ tpl;
$ Tpl-> parse ('output', 'main ');
$ Tpl-> p ('output ');
}
/**
* Email sending Function
*
* @ Access public private
* @ Param bool
* @ Return void
*/
Function mailSender ($ from, $ to, $ title, $ content ){
$ From? $ From = 'sender @ phpe.net ':'';
$ Title? $ Title = 'from Exceed PHP ...':'';
$ Sig ="
Thank you for using our service. \ n
Exceed PHP (beyond PHP) \ n
$ Maildate \ n
Bytes ---------------------------------------------------------------------------------------
\ N
The only way to discover the limit method is to surpass it \ n
Beyond PHP welcome (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 Parsing
*
* @ Param none
* @ Access public
* @ Return void
*/
Function ubbParse ($ txt, $ coverhtml = 0 ){
If ($ coverhtml = 0) $ txt = nl2br (new_htmlspecialchars ($ txt); // convert BR and HTML
// Only convert BR, not 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 supports the sequence set.
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 * \ & quot \;([\. \ w \-] + \@[\. \ w \-] + \. [\. \ w \-] +) \ s * \ & quot \; \ 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 * \ & quot \; \ s * (\ S + ?) \ S * \ & quot \; \ 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 ","

// Images
$ Txt = preg_replace ("# \ [img \] (. + ?) \ [/Img \] # I ", "<a href = '\ 1' target =' _ blank '> 500) this. width = 500 'align = 'center' hspace = '10' vspace = '10'> </a> <br/> ", $ txt );
// Attach
$ Txt = preg_replace ("# \ [attach \ s * = \ s * \ & quot \; \ s * (\ S + ?) \ S * \ & quot \; \ s * \] (. *?) \ [\/Attach \] # I "," <a href = '\ 2' target =' _ blank '> <B> related attachments: </B> \ 1 </a> ", $ txt );
$ Txt = preg_replace ("# \ [attach \ s * = \ s * (\ S + ?) \ S * \] (. *?) \ [\/Attach \] # I "," <a href = '\ 2' target =' _ blank '> <B> related attachments: </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'> open a link in a new window </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;
}
// Reformat the date
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 );
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.