php常用函数3
<?php
class useful{
/*
* 常用函数类
* 作 者:多菜鸟
* 联系邮箱:kingerq AT msn DOT com
* 创建时间:2005-07-18
* 来源:http://blog.csdn.net/kingerq
*/
/*
* 功能:格式化数字,以标准MONEY格式输出
*/
function formatnumber($num){
return number_format($num, 2, ".", ",");
}
/*
* 功能:格式化文本,将\n转成<br>等
* 参数:$string 来源字符串
* 返回:处理后的字符串
*/
function formatstring($string = ""){
$string = preg_replace(array("/\s+/", "/\'/"), array(" ", "\"\""), $string);
$string = htmlspecialchars($string);
return nl2br($string);
}
/*
* 功能:格式化文本输出
* 参数 $text 为需格式化的文本内容
* 慎用,如果让用户输入的可执行代码在formatstring处理后插如数据库,然后使用此函数会让代码执行
*/
function formatcontent($text){
$trans = get_html_translation_table(HTML_SPECIALCHARS);
$trans = array_flip($trans);
$text = strtr($text, $trans);
//$text = str_replace("\n", "<br>", $text);
//$text = str_replace(" ", " ", $text);
return $text;
}
/*
* 将字节转换成Kb或者Mb...
* 参数 $num为字节大小
*/
function bitsize($num){
if(!preg_match("/^[0-9]+$/", $num)) return 0;
$type = array( "B", "KB", "MB", "GB", "TB", "PB" );
$j = 0;
while( $num >= 1024 ) {
if( $j >= 5 ) return $num.$type[$j];
$num = $num / 1024;
$j++;
}
return $num.$type[$j];
}
/*
* 功能:不足3的倍数位的数字,用0补足
* $num 需补充的数字
* 返回补充完整的数字串
*/
function prefix($num){
if( strlen( $num ) % 3 == 0 ) {
return $this-
相关文档:
#apt-get install apache2
//安装apahce2
#apt-get install php5
//安装php5
#apt-get install mysql-server
//安装mysql服务端
#apt-get install mysql-myclient
//安装mysql的客户端
#apt-get install php-mysql
//安装php-mysql的连结
apache+php+mysql 环境已经搭建好了
将以下的服务重启一下
#/et ......
随 着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流 行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。
下面的例子是将、index.asp?i ......
<?php
error_reporting(0);//7all,0no
ini_set('display_errors', '0');
function myerror($errno, $errstr, $errfile, $errline)
{
echo "<BR>error type: [$errno] $errstr<br />\n";
echo "in line $errline of file $errfile<BR>";
} ......
1.产生随机字符串函数
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$ha ......
文件读取函式
//文件读取函式
function PHP_Read($file_name) {
$fd=fopen($file_name,r);
while($bufline=fgets($fd, 4096)){
$buf.=$bufline;
}
fclose($fd);
return $buf;
}
& ......