闲者博客 - 获取 2022-02-25T18:51:51+08:00 Typecho https://bk1314.com/feed/atom/tag/%E8%8E%B7%E5%8F%96/ <![CDATA[PHP获取当前页面URL]]> https://bk1314.com/39.html 2022-02-25T18:51:51+08:00 2022-02-25T18:51:51+08:00 飞鱼 http://www.typecho.org 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(); ]]> <![CDATA[PHP获取文件扩展名(后缀)]]> https://bk1314.com/37.html 2022-02-25T18:49:56+08:00 2022-02-25T18:49:56+08:00 飞鱼 http://www.typecho.org function getExtension($filename){ $myext = substr($filename, strrpos($filename, '.')); return str_replace('.','',$myext); } $filename = '我的文档.doc'; echo getExtension($filename); ]]> <![CDATA[PHP获取文件大小并格式化]]> https://bk1314.com/36.html 2022-02-25T18:48:25+08:00 2022-02-25T18:48:25+08:00 飞鱼 http://www.typecho.org 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); ]]>