【www.gdgbn.com--php函数】
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_badwords"];
$rg_banname=explode(",",$rg_banname);
foreach($rg_banname as $value){
if(strpos($str,$value)!==false){
//$from = strtr($str,$value,$to);
$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 = "0123456789abcdefghijklmnopqrstuvwxyz";
$str = "";
while(strlen($str) < $length) $str .= substr($possible, (rand() % strlen($possible)), 1);
return($str);
}