PHP方法总结
编程时间长了,大家见过很多函数功能吧,比如获取用户IP等等,现在我将常用的PHP函数做个总结,方便大家COPY和使用。 <?php //获取用户IP function getIp() { $ip = ""; if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknow')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('REMOTE_ADD') && strcasecmp(getenv('REMOTE_ADD'), 'unknow')) { $ip = getenv('REMOTE_ADD'); } elseif (isset($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknow')) { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } //快速替换字符串 //$arrayName = array('h'=>'s','o'=>'t','l'=>'xx'); //echo strsReplace('hello',$arrayName); function strsReplace($str, $replaces) { $subject=$str; foreach ($replaces as $k => $v) $subject = str_replace($k, $v, $subject); return $subject; } //规范文件名 //$filename='"<>/\\\asda/.,psd|"'; //echo tripFilename($filename); function tripFilename($filename) { //$s=array("/","\\","?...