There are 0 fill, intercept Chinese, halt, html jump, JS jump, filter HTML, check the legality of the mailbox, convert the text in the hyperlink as clickable connection, return time format and so on commonly used PHP function library.
- Because both front and rear stations need to be used, so put in the Supermario folder for easy reuse
- /**
- * Oh ~ the lovely drop of the decimal ~ Oh ~ the lovely thousand ~
- * If the number of digits exceeds 4 digits, the 3rd digit will be increased before
- * @param int $gold
- * @return String
- */
- function Showgold ($gold) {
- Return Number_format ($gold);
- }
- /**
- * Page Compression output
- */
- function Ob_callback ($buffer) {
- Header (' Etag: '. MD5 ($buffer));
- if (extension_loaded (' zlib ') and Strstr ($_server["http_accept_encoding"], "gzip")) {
- $buffer = Gzencode ($buffer, 9);
- Header (' Content-encoding:gzip ');
- Header (' vary:accept-encoding ');
- Header (' Via:www.guangxitravel.cn ');
- Header (' Content-length: '. strlen ($buffer));
- }
- return $buffer;
- }
- /**
- * Skip the page without prompting
- * @param string $url
- * @param string $target
- */
- function Go ($url = ', $target = ' parent ') {
- if ($url! = "") {
- Echo (');
- } else {
- Echo (');
- }
- }
- /**
- * Clear the cache, ECHO, then die (hateful javascript+php ...) Plain text output, there will always be some empty characters ... )
- * @param string $msg
- */
- function Justsay ($msg) {
- Ob_clean ();
- Die ($msg);
- }
- /**
- * Replace the contents of the first parameter in the second parameter with the red one
- * @param string $data
- * @param array $keyword
- * @return String
- */
- function Change_keyword ($data, $keywords) {
- if (Is_array ($keywords)) {
- foreach ($keywords as $k = = $v) {
- $data = Str_replace ($v, ". $v. ", $data);
- }
- return $data;
- } else {
- Return Str_replace ($keywords, ". $keywords. ", $data);
- }
- }
- /**
- * Create a completely random color
- * @return String
- */
- function Makecolor () {
- $key = ' # ';
- for ($i = 0; $i < 6; $i + +)
- $key. = rand (0, 9);//Generate PHP random number
- return $key;
- }
- /**
- * Automatic loading of models and third-party function classes
- * @param string $className
- */
- function AutoLoad ($className) {
- if (strstr ($_server[' Request_uri '), "/operator/") = = False) {//server does not support Script_url
- if (File_exists (siteroot. '/client/model/'. $className. '. php ')} {
- Require_once Siteroot. '/client/model/'. $className. '. php ';
- Return
- }
- } else {
- if (File_exists (siteroot. '/manager/model/'. $className. '. php ')} {
- Require_once Siteroot. '/manager/model/'. $className. '. php ';
- Return
- }
- }
- if (File_exists (siteroot. '/public/modules/'. $className. '. php ')} {
- Require_once Siteroot. '/public/modules/'. $className. '. php ';
- Return
- }
- if (File_exists (siteroot. '/client/order/model/'. $className. '. php ')} {
- Require_once Siteroot. '/client/order/model/'. $className. '. php ';
- Return
- }
- }
- /**
- * Pop up a message with JavaScript
- * @param $message
- */
- Function message ($message = ") {
- Echo (');
- }
- /**
- * Simulates the third parameter of STRSTR (), returns the data before the $h, $n
- *//$h = haystack, $n = needle
- * @param $h
- * @param $n
- * @return
- */
- function Strstrb ($h, $n) {
- Return Array_shift (Explode ($n, $h, 2));
- }
- /**
- * Display error message and jump to $pageurl, including style
- *
- * @param string $messages
- * @param string $pageurl
- * @param int $msc number of seconds
- */
- function msg ($messages, $pageurl = ' javascript:history.back (); ', $msc =5) {
- Echo 'System Message
Web System Message
- ', $messages, '
>>> Please click here to return
- ';
- Exit ();
- }
- /**
- * Check if the later date is greater than the previous date
- * @param type $datecome the previous date
- * @param the date after type $datego
- * @return Type
- */
- function Sub_date ($datecome, $datego) {
- $d 1 = strtotime ($datecome);
- $d 2 = strtotime ($datego);
- $days = Round (($d 2-$d 1)/3600/24);
- $days = $days < 1? 0: $days;
- return $days;
- }
- /**
- * Replace the contents of the $length behind $string with $dot
- * @param string $string
- * @param int $length
- * @param string $dot
- * @return String
- */
- function Cutstr ($string, $length, $dot = ' ... ') {
- @extract ($string);
- if (strlen ($string) <= $length) {
- return $string;
- }
- $string = Htmlspecialchars ($string);
- $string = Str_replace (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' "', ' < ', ' > '), $string);
- $strcut = ";
- $n = $tn = $noc = 0;
- while ($n < strlen ($string)) {
- $t = Ord ($string [$n]);
- if ($t = = 9 | | $t = = 10 | | (<= $t && $t <= 126)) {
- $tn = 1;
- $n + +;
- $noc + +;
- } elseif (194 <= $t && $t <= 223) {
- $tn = 2;
- $n + = 2;
- $noc + = 2;
- } elseif (224 <= $t && $t < 239) {
- $tn = 3;
- $n + = 3;
- $noc + = 2;
- } elseif (<= $t && $t <= 247) {
- $tn = 4;
- $n + = 4;
- $noc + = 2;
- } elseif (248 <= $t && $t <= 251) {
- $tn = 5;
- $n + = 5;
- $noc + = 2;
- } elseif ($t = = 252 | | $t = = 253) {
- $tn = 6;
- $n + = 6;
- $noc + = 2;
- } else {
- $n + +;
- }
- if ($noc >= $length) {
- Break
- }
- }
- if ($noc > $length) {
- $n-= $tn;
- }
- $strcut = substr ($string, 0, $n);
- $strcut = Str_replace (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' "', ' < ', ' > '), $strcut);
- Return $strcut. $dot;
- }
- /**
- +----------------------------------------------------------
- * If MAGIC_QUOTES_GPC is turned on, use this method to increment the transfer symbol before using it as a special symbol
- +----------------------------------------------------------
- * @access Public
- +----------------------------------------------------------
- * @param string $value can be an array
- +----------------------------------------------------------
- * @return String
- +----------------------------------------------------------
- */
- function Kaddslashes ($value) {
- return $value = Is_array ($value)? Array_map (' kaddslashes ', $value): Addslashes ($value);
- }
- /**
- +----------------------------------------------------------
- * Remove the transfer symbol before the special symbol
- +----------------------------------------------------------
- * @access Public
- +----------------------------------------------------------
- * @param string $value can be an array
- +----------------------------------------------------------
- * @return String
- +----------------------------------------------------------
- */
- function Kstripcslashes ($value) {
- return $value = Is_array ($value)? Array_map (' kstripcslashes ', $value): Stripcslashes ($value);
- }
- /**
- * The string content HTML is manifested to avoid some illegal information directly executed. If the argument is an array, it is recursive.
- * @param string $value
- * @return Array
- */
- function Khtmlspecialchars ($value) {
- Return Is_array ($value)? Array_map (' Khtmlspecialchars ', $value):
- Preg_replace ('/& (# (\d{3,5}|x[a-fa-f0-9]{4}) |[ a-za-z][a-z0-9]{2,5});)/', ' &\\1 ', Str_replace (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' "', ' < ', ' > '), $value));
- }
- /**
- * The HTML in the string is removed, if the argument is an array, then recursion.
- * @param string $value
- * @return Array
- */
- function Striptags ($value) {
- return $value = Is_array ($value)? Array_map (' Striptags ', $value): Strip_tags ($value);
- }
- /**
- * Check the legality of email
- *
- * @param string $email
- * @return BOOL
- */
- function Check_email ($email) {
- if (Preg_match ("/[a-z0-9]*[-_\.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,3} ([\.] [A-z] {2})? /i ", $email)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Secure Email address
- *
- * @param string $email
- * @param string $title
- * @param $attributes
- * @return
- */
- function Safe_mailto ($email, $title = ', $attributes = ') {
- if (Is_array ($email)) {
- $tmp = $email;
- Unset ($email);
- Extract ($tmp);
- }
- $title = (string) $title;
- if ($title = = "") {
- $title = $email;
- }
- for ($i = 0; $i < $i + +) {
- $x [] = substr ('}
- for ($i = 0; $i < strlen ($email); $i + +) {
- $x [] = "|". Ord (substr ($email, $i, 1));
- }
- $x [] = ' "';
- if ($attributes! = ") {
- if (Is_array ($attributes)) {
- foreach ($attributes as $key = = $val) {
- $x [] = '. $key. '="';
- for ($i = 0; $i < strlen ($val); $i + +) {
- $x [] = "|". Ord (substr ($val, $i, 1));
- }
- $x [] = ' "';
- }
- } else {
- for ($i = 0; $i < strlen ($attributes); $i + +) {
- $x [] = substr ($attributes, $i, 1);
- }
- }
- }
- $x [] = ' > ';
- $temp = Array ();
- for ($i = 0; $i < strlen ($title); $i + +) {
- $ordinal = Ord ($title [$i]);
- if ($ordinal < 128) {
- $x [] = "|". $ordinal;
- } else {
- if (count ($temp) = = 0) {
- $count = ($ordinal < 224)? 2:3;
- }
- $temp [] = $ordinal;
- if (count ($temp) = = $count) {
- $number = ($count = = 3)? (($temp [' 0 ']%) * 4096) + (($temp [' 1 ']% *) + ($temp [' 2 ']%): (($temp [' 0 ']%) * + ($temp [' 1 ']% 64);
- $x [] = "|". $number;
- $count = 1;
- $temp = Array ();
- }
- }
- }
- $x [] = ' < ';
- $x [] = '/';
- $x [] = ' a ';
- $x [] = ' > ';
- $x = Array_reverse ($x);
- Ob_start ();
- ?> $buffer = ob_get_contents ();
- Ob_end_clean ();
- if ($tmp = = "| | $tmp = = NULL) {
- return $buffer;
- } else {
- Echo $buffer;
- }
- }
- /**
- +----------------------------------------------------------
- * Convert the hyperlinks in text to clickable links
- +----------------------------------------------------------
- * @access Public
- +----------------------------------------------------------
- * @param string $text to be processed
- +----------------------------------------------------------
- * @return String
- +----------------------------------------------------------
- */
- function Makelink ($string) {
- $validChars = "a-z0-9\/\-_+=.~!%@?#&;:$\|";
- $patterns = Array (
- "/(^| [^]_a-z0-9-=\ "'/]") ([a-z]+?): \ /\/([{$validChars}]+)/ei ",
- "/(^| [^]_a-z0-9-=\ "' \ \]") www\. ([a-z0-9\-]+) \. ([{$validChars}]+)/ei ",
- "/(^| [^]_a-z0-9-=\ "' \ \]") ftp\. ([a-z0-9\-]+) \. ([{$validChars}]+)/ei ",
- "/(^| [^]_a-z0-9-=\ "' \/:\.]) ([A-z0-9\-_\.] +?) @ ([{$validChars}]+)/ei ");
- $replacements = Array (
- "' \\1\\2://'. Input::truncate (' \\3 '). ' ",
- "' \\1 '. Input::truncate (' www.\\2.\\3 '). ' ",
- "' \\1 '. Input::truncate (' ftp.\\2.\\3 '). ' ",
- "' \\1 '. Input::truncate (' \\2@\\3 ').
- Return Preg_replace ($patterns, $replacements, $string);
- }
- /**
- * Get client browser
- * @return String
- */
- function Browse_info () {
- $browser = "";
- $browserver = "";
- $Browsers = Array ("Lynx", "MOSAIC", "AOL", "Opera", "JAVA", "Macweb", "Webexplorer", "OmniWeb");
- $Agent = $_server["Http_user_agent"]; Global variables of the browser
- for ($i = 0; $i <= 7; $i + +) {
- if (Strpos ($Agent, $Browsers [$i])) {
- $browser = $Browsers [$i];
- $browserver = "";
- }
- }
- if (Ereg ("Mozilla", $Agent) && ereg ("MSIE", $Agent)) {
- $temp = Explode ("(", $Agent);
- $Part = $temp [1];
- $temp = Explode (";", $Part);
- $Part = $temp [1];
- $temp = Explode ("", $Part);
- $browserver = $temp [2];
- $browserver =preg_replace ("/([D.] +)/"," 1 ", $browserver);
- $browserver = "IE". $browserver;
- $browser = "IE";
- }
- if (Ereg ("Mozilla", $Agent) &&!ereg ("MSIE", $Agent)) {
- $temp = Explode ("(", $Agent);
- $Part = $temp [0];
- $temp = Explode ("/", $Part);
- $browserver = $temp [1];
- $temp = Explode ("", $browserver);
- $browserver = $temp [0];
- $browserver = Preg_replace ("/([D.] +)/"," 1 ", $browserver);
- $browserver = "$browserver";
- $browser = "Netscape Navigator";
- }
- if (Ereg ("Mozilla", $Agent) && ereg ("Opera", $Agent)) {
- $temp = Explode ("(", $Agent);
- $Part = $temp [1];
- $temp = Explode (")", $Part);
- $browserver = $temp [1];
- $temp = Explode ("", $browserver);
- $browserver = $temp [2];
- $browserver = Preg_replace ("/([\d\.] +)/"," 1 ", $browserver);
- $browserver = "$browserver";
- $browser = "Opera";
- }
- Firefox browser
- if (Ereg ("Mozilla", $Agent) && ereg ("Firefox", $Agent)) {
- $temp = Explode ("(", $Agent);
- $Part = $temp [1];
- $temp = Explode (")", $Part);
- $browserver = $temp [1];
- $temp = Explode ("", $browserver);
- $browserver = $temp [2];
- $browser = "Firefox";
- }
- Google Chrome
- if (Ereg ("Mozilla", $Agent) && ereg ("Chrome", $Agent)) {
- $temp = Explode ("(", $Agent);
- $temp = Explode ("", $temp [2]);
- $browserver = $temp [' 3 ']; If Google does not change the location in the future, it is.
- $browser = "Google";
- }
- 360safe Browser
- if (Ereg ("Mozilla", $Agent) && ereg ("360SE", $Agent)) {
- Because 360 browsers, no version ...
- $browserver = $browser = "360 security guard";
- }
- if ($browser! = "") {
- $browseinfo = $browser. $browserver;
- $browseinfo = $browserver;
- } else {
- $browseinfo = "Unknown";
- }
- return $browseinfo;
- }
- /**
- * Return time format
- * @name: Preparedate
- * @desc: Prepares a date in the proper format for specific database types
- * Given a UNIX timestamp
- * @param: $timestamp: a UNIX timestamp
- * @param: $fieldType: The type of field to format the date for
- * (in MySQL, you had DATE, time, year, and DATETIME)
- */
- function Preparedate ($timestamp, $fieldType = ' DATETIME ') {
- $date = ";
- if (! $timestamp = = = False && $timestamp > 0) {
- Switch ($fieldType) {
- Case ' DATE ':
- $date = Date (' y-m-d ', $timestamp);
- Break
- Case ' time ':
- $date = Date (' h:i:s ', $timestamp);
- Break
- Case ' Year ':
- $date = Date (' Y ', $timestamp);
- Break
- Default:
- $date = Date (' y-m-d h:i:s ', $timestamp);
- Break
- }
- }
- return $date;
- }
- /**
- * Adapts to the recursion of multidimensional arrays, and removes the duplicate values and returns
- * @param array $array
- * @return Array
- */
- function Super_unique ($array) {
- $result = Array_map ("Unserialize", Array_unique (Array_map ("Serialize", $array)));
- foreach ($result as $key = = $value) {
- if (Is_array ($value)) {
- $result [$key] = Super_unique ($value);
- }
- }
- return $result;
- }
- /**
- * If the value does not meet 2 bits, auto-fill 0
- * @param int $num
- * @return int
- */
- function Fullzero ($num) {
- if (strlen ($num)!=2) {
- Return ' 0 '. $num;
- }else{
- return $num;
- }
- }
- Return to previous URL
- function Get_visit_url () {
- Return $_server[' Http_referer '];
- }
- ?>
Copy Code |