⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 08c02-2.php

📁 介绍PHP5的给类型函数应用
💻 PHP
字号:
<?php// A function to format the bytes of a file, as a natural looking string.// This version handles it via 1024 based logic:function format_bytes($bytes) {	// Define an array of the different display forms:	$display = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');		// Now, constantly divide the value by 1024 until it is less than 1024	$level = 0;	while ($bytes > 1024) {		$bytes /= 1024;		$level++;	}	// Now we have our final value, format it to just 1 decimal place	// and append on to the the appropriate level moniker.	return round($bytes, 1) . ' ' . $display[$level];}// Echo out a few examples to test the function:echo '<p>4200 bytes = ', format_bytes(4200), "<p>\n"; // 4.1 kBecho '<p>420000 bytes = ', format_bytes(420000), "<p>\n"; // 410.2 kBecho '<p>42000000 bytes = ', format_bytes(42000000), "<p>\n"; // 40.1 MB?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -