Common functions in php-PHP source code

Source: Internet
Author: User
Ec (2); functiongetip () {& nbsp; if (getenv (http_client_ip) & amp; strcasecmp (getenv (http_client_ip), unknown) {& nbsp; & nbsp; $ onlineipgetenv (http_client_ip); & nbsp;} elseif (getenv (h script ec (2); script

Function getip (){
If (getenv ('HTTP _ client_ip ') & strcasecmp (getenv ('HTTP _ client_ip'), 'unknown ')){
$ Onlineip = getenv ('HTTP _ client_ip ');
} Elseif (getenv ('HTTP _ x_forwarded_for ') & strcasecmp (getenv ('HTTP _ x_forwarded_for'), 'unknown ')){
$ Onlineip = getenv ('HTTP _ x_forwarded_for ');
} Elseif (getenv ('remote _ addr ') & strcasecmp (getenv ('remote _ addr'), 'unknown ')){
$ Onlineip = getenv ('remote _ addr ');
} Elseif (isset ($ _ server ['remote _ addr ']) & $ _ server ['remote _ addr '] & strcasecmp ($ _ server ['remote _ addr'], 'unknown ')){
$ Onlineip = $ _ server ['remote _ addr '];
}
$ Onlineip = preg_replace ("/^ ([d.] +). */", "1", $ onlineip );
Return $ onlineip;
}

Function htmlout ($ str ){
$ Guest = $ str;
$ Guest = str_replace ("&", "&", $ guest );
$ Guest = str_replace ("", "", $ guest );
// $ Guest = str_replace ("", "", $ guest );
$ Guest = str_replace ("", "", $ guest );
// $ Guest = htmlspecialchars ($ guest );
$ Guest = str_replace (">", ">", $ guest );
$ Guest = str_replace ("<", "<", $ guest );
$ Guest = str_replace ("rn ","
", $ Guest );
$ Guest = str_replace ("'", "'", $ guest );
$ Guest = str_replace ("", ", $ guest );
Return ($ guest );
}
Function badstr ($ str, $ to = '*'){
Global $ global;
$ From = $ str;
$ Rg_banname = $ global ['m _ badword'];
$ Rg_banname = explode (',', $ rg_banname );
Foreach ($ rg_banname as $ value ){
If (strpos ($ str, $ value )! = False ){
// $ From = strtr ($ str, $ value, $ );
$ From = str_replace ($ value, $ to, $ from );
}
}
Return ($ from );
}
Function mkpath ($ mkpath, $ mode = 0777 ){
$ Path_arr = explode ('/', $ mkpath );
Foreach ($ path_arr as $ value ){
If (! Empty ($ value )){
If (empty ($ path) $ path = $ value;
Else $ path. = '/'. $ value;
Is_dir ($ path) or mkdir ($ path, $ mode) or chmod ($ path, $ mode );
}
}
If (is_dir ($ mkpath) return true;
Return false;
}
Function daddslashes ($ string, $ force = 0 ){
Global $ magic_quotes_gpc;
If (! $ Globals ['Magic _ quotes_gpc '] | $ force | $ magic_quotes_gpc ){
If (is_array ($ string )){
Foreach ($ string as $ key => $ val ){
$ String [$ key] = daddslashes ($ val, $ force );
}
} Else {
$ String = addslashes ($ string );
}
}
Return $ string;
}
Function dhtmlspecialchars ($ string ){
If (is_array ($ string )){
Foreach ($ string as $ key => $ val ){
$ String [$ key] = dhtmlspecialchars ($ val );
}
} Else {
$ String = preg_replace ('/& (# (d {3, 5} | x [a-fa-f0-9] {4 }) | [a-za-z] [a-z0-9] {2, 5});)/',' & 1 ',
Str_replace (array ('&', '"', '<', '>'), array ('&', '"', '<', '> '), $ string ));
}
Return $ string;
}
Function trimm ($ str ){
$ Str = trim (str_replace ("", "", $ str ));
// $ Str = str_replace ("'", "'", $ str );
Return $ str;
}
Function cdstr ($ length ){
$ Possible = "0123456789 ";
$ Str = "";
While (strlen ($ str) <$ length) $ str. = substr ($ possible, (rand () % strlen ($ possible), 1 );
Return ($ str );
}
Function cdstrletters ($ length ){
$ Possible = "abcdefghijklmnopqrstuvwxyz ";
$ Str = "";
While (strlen ($ str) <$ length) $ str. = substr ($ possible, (rand () % strlen ($ possible), 1 );
Return ($ str );
}
Function cdnumletters ($ length ){
$ Possible = "0123456789 abcdefghijklmnopqrstuvwxyz ";
$ Str = "";
While (strlen ($ str) <$ length) $ str. = substr ($ possible, (rand () % strlen ($ possible), 1 );
Return ($ str );
}

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.