当前位置:Gxlcms > PHP教程 > 史上最全的PHP常用函数大全,不看看你就out了(还会不断更新哦!)_PHP教程

史上最全的PHP常用函数大全,不看看你就out了(还会不断更新哦!)_PHP教程

时间:2021-07-01 10:21:17 帮助过:71人阅读







sub_str(, = 0, = = (); = ( ( == 0 || >= ( < 0 = + ( < 0 = (('mb_substr' = mb_substr(, 0, , (('iconv_substr' = (, 0, , = (, 0, ( && != .= '...' } View Code

2、获得用户的真实IP地址

= ( !== (( ((['HTTP_X_FORWARDED_FOR' = (',', ['HTTP_X_FORWARDED_FOR' ( = ( ( != 'unknown' = ((['HTTP_CLIENT_IP' = ['HTTP_CLIENT_IP' ((['REMOTE_ADDR' = ['REMOTE_ADDR' = '0.0.0.0' (('HTTP_X_FORWARDED_FOR' = ('HTTP_X_FORWARDED_FOR' (('HTTP_CLIENT_IP' = ('HTTP_CLIENT_IP' = ('REMOTE_ADDR' ("/[\d\.]{7,15}/", , = !([0]) ? [0] : '0.0.0.0' } View Code

3、计算字符串的长度(汉字按照两个字符计算)

str_len( = (('/[\x00-\x7F]/', '', ( () - + ( / 3) * 2 ( } View Code

4、获得用户操作系统的换行符

((['HTTP_USER_AGENT'], 'Win' = '\r\n' ((['HTTP_USER_AGENT'], 'Mac' = '\r'; = '\n' } View Code

5、邮件发送

send_mail(, , , , = 0, = (['_CFG']['mail_charset'] != = ecs_iconv(EC_CHARSET, ['_CFG']['mail_charset'], = ecs_iconv(EC_CHARSET, ['_CFG']['mail_charset'], = ecs_iconv(EC_CHARSET, ['_CFG']['mail_charset'], = ecs_iconv(EC_CHARSET, ['_CFG']['mail_charset'], ['_CFG']['shop_name' = ['_CFG']['mail_charset' (['_CFG']['mail_service'] == 0 && ('mail' = ( == 0) ? 'Content-Type: text/plain; charset=' . : 'Content-Type: text/html; charset=' . = [] = 'From: "' . '=?' . . '?B?' . () . '?='.'" <' . ['_CFG']['smtp_mail'] . '>' [] = . '; format=flowed' ( [] = 'Disposition-Notification-To: ' . '=?' . . '?B?' . () . '?='.'" <' . ['_CFG']['smtp_mail'] . '>' = @(, '=?' . . '?B?' . () . '?=', , ("\r\n", (! ['err'] ->add(['_LANG']['sendemail_false' = ( == 0) ? 'Content-Type: text/plain; charset=' . : 'Content-Type: text/html; charset=' . = ( = [] = 'Date: ' . ('D, j M Y H:i:s') . ' +0000' [] = 'To: "' . '=?' . . '?B?' . () . '?=' . '" <' . . '>' [] = 'From: "' . '=?' . . '?B?' . () . '?='.'" <' . ['_CFG']['smtp_mail'] . '>' [] = 'Subject: ' . '=?' . . '?B?' . () . '?=' [] = . '; format=flowed' [] = 'Content-Transfer-Encoding: base64' [] = 'Content-Disposition: inline' ( [] = 'Disposition-Notification-To: ' . '=?' . . '?B?' . () . '?='.'" <' . ['_CFG']['smtp_mail'] . '>' ['host'] = ['_CFG']['smtp_host' ['port'] = ['_CFG']['smtp_port' ['user'] = ['_CFG']['smtp_user' ['pass'] = ['_CFG']['smtp_pass' ((['host']) || (['port' ['err'] ->add(['_LANG']['smtp_setting_error' (!('fsockopen' ['err']->add(['_LANG']['disabled_fsockopen' (ROOT_PATH . 'includes/cls_smtp.php' ['recipients'] = ['headers'] = ['from'] = ['_CFG']['smtp_mail' ['body'] = (!( = smtp( (->connect() && ->send( = -> (( ['err']->add('Unknown Error' ((, 'Failed to connect to server') !== ['err']->add((['_LANG']['smtp_connect_failure'], ['host'] . ':' . ['port' ((, 'AUTH command failed') !== ['err']->add(['_LANG']['smtp_login_failure' ((, 'bad sequence of commands') !== ['err']->add(['_LANG']['smtp_refuse' ['err']->add( } View Code

6、获得服务器上的 GD 版本

(ROOT_PATH . 'includes/cls_image.php' cls_image:: (!('file_get_contents' ( (( = @(, 'rb')) === = @( ( = (, = '' ( (!('file_put_contents' ('FILE_APPEND', 'FILE_APPEND' (, , = '' = (()) ? ('', ) : ( == 'FILE_APPEND' = 'ab+' = 'wb' (( = @(, )) === = (, ( (!('floatval' ( () } View Code

7、文件或目录权限检查函数

file_mode_info( (!( = 0 (((, 0, 3)) == 'WIN' = . '/cf_test.txt' (( = @( ( === ; (@() !== ^= 1; @( = @(, 'wb' ( === ; (@(, 'directory access testing.') !== ^= 2; @( @( = @(, 'ab+' ( === (@(, "modify test.\r\n") !== ^= 4 @( (@(, ) !== ^= 8 @( (( = @(, 'rb' ( ^= 1; @( = @(, 'ab+' ( && @(, '') !== ^= 6; @( (@(, ) !== ^= 8 (@( ^= 1 (@( ^= 14 log_write(, = '', = '' ((DEBUG_MODE & 4) != 4 = "\r\n-- ". ('Y-m-d H:i:s'). " --------------------------------------------------------------\r\n" .= "FILE: \r\nLINE: \r\n" (( .= '$arg = array(' ( ( => .= "'' => ''\r\n" .= ")\r\n" .= (ROOT_PATH . DATA_DIR . '/log.txt', } View Code

8、检查目标文件夹是否存在,如果不存在则自动创建该目录

make_dir( = (!( @(0 ('/([^\/]*)\/?/i', , = ([0][0] == '/') ? '/' : '' ([1] ('' != .= ('..' == || '.' == .= '/' .= '/' (!( (@((, '/'), 0777 @(, 0777 = = ( } View Code

9、获得系统是否启用了 gzip

= ( === = (['_CFG']['enable_gzip'] && ('ob_gzhandler' } View Code

10、递归方式的对变量中的特殊字符进行转义

addslashes_deep( (( () ? ('addslashes_deep', ) : ( } View Code

11、将对象成员变量或者数组的特殊字符进行转

addslashes_deep_obj( (() == ( => -> = addslashes_deep( = addslashes_deep( } View Code

12、递归方式的对变量中的特殊字符去除转义

stripslashes_deep( (( () ? ('stripslashes_deep', ) : ( } View Code

13、将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符

make_semiangle( = ('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O', 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y', 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[', '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']', '‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<', '》' => '>', '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-', ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.', ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|', '”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"', ' ' => ' ' (, } View Code

14、 过滤用户输入的基本数据,防止script攻击

compile_str( = ('<' => '<', '>' => '>' (, } View Code

15、检查文件类型

check_file_type(, = '', = '' ( = ((, (, '.') + 1 = ((, (, '.') + 1 ( && (, '|' . . '|') === '' = = '' = @(, 'rb' ( = @(, 0x400); @( ((, ROOT_PATH) === ( == 'jpg' || == 'jpeg' || == 'gif' || == 'png' || == 'doc' || == 'xls' || == 'txt' || == 'zip' || == 'rar' || == 'ppt' || == 'pdf' || == 'rm' || == 'mid' || == 'wav' || == 'bmp' || == 'swf' || == 'chm' || == 'sql' || == 'cert'|| == 'pptx' || == 'xlsx' || == 'docx' = '' ( == '' && () >= 2 ((, 0, 4) == 'MThd' && != 'txt' = 'mid' ((, 0, 4) == 'RIFF' && == 'wav' = 'wav' (( ,0, 3) == "\xFF\xD8\xFF" = 'jpg' (( ,0, 4) == 'GIF8' && != 'txt' = 'gif' (( ,0, 8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" = 'png' (( ,0, 2) == 'BM' && != 'txt' = 'bmp' ((( ,0, 3) == 'CWS' || ( ,0, 3) == 'FWS') && != 'txt' = 'swf' (( ,0, 4) == "\xD0\xCF\x11\xE0" { ((,0x200,4) == "\xEC\xA5\xC1\x00" || == 'doc' = 'doc' ((,0x200,2) == "\x09\x08" || == 'xls' = 'xls' } ((,0x200,4) == "\xFD\xFF\xFF\xFF" || == 'ppt' = 'ppt' } (( ,0, 4) == "PK\x03\x04" ((,0x200,4) == "\xEC\xA5\xC1\x00" || == 'docx' = 'docx' ((,0x200,2) == "\x09\x08" || == 'xlsx' = 'xlsx' } ((,0x200,4) == "\xFD\xFF\xFF\xFF" || == 'pptx' = 'pptx' } = 'zip' } (

人气教程排行