闲者博客 - 获取 https://bk1314.com/tag/%E8%8E%B7%E5%8F%96/ PHP获取当前页面URL https://bk1314.com/39.html 2022-02-25T18:51:51+08:00 function curPageURL() { $pageURL = 'http'; if (!empty($_SERVER['HTTPS'])) {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } echo curPageURL(); PHP获取文件扩展名(后缀) https://bk1314.com/37.html 2022-02-25T18:49:56+08:00 function getExtension($filename){ $myext = substr($filename, strrpos($filename, '.')); return str_replace('.','',$myext); } $filename = '我的文档.doc'; echo getExtension($filename); PHP获取文件大小并格式化 https://bk1314.com/36.html 2022-02-25T18:48:25+08:00 function formatSize($size) { $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); if ($size == 0) { return('n/a'); } else { return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); } } $thefile = filesize('test_file.mp3'); echo formatSize($thefile);