易截截图软件、单文件、免安装、纯绿色、仅160KB

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(" ", "&nbsp;", $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-


相关文档:

php显示时间代码

一、PHP函数Date()获取当前时间
代码:
<?php echo $showtime=date("Y-m-d H:i:s");?>
显示的格式: 年-月-日 小时:分钟:秒
相关参数:
a:"am"或者"pm"
A:"AM"或者"PM"
d:几日,二位数字,若不足二位则前面补零,如: "01"至"31"
D:星期几,三个英文字母,如: "Fri"
F:月份,英文全名,如: "Jan ......

php中substr的用法详解

php中substr的用法详解
php.net中关于substr的说明很简单:
start
If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so for ......

PHP中$_SERVER的详解

 $_SERVER['PHP_SELF']
#当前正在执行脚本的文件名,与 document root相关。
$_SERVER['argv']
#传递给该脚本的参数。
$_SERVER['argc']
#包含传递给程序的命令行参数的个数(如果运行在命令行模式)。
$_SERVER['GATEWAY_INTERFACE']
#服务器使用的 CGI 规范的版本。例如,“CGI/1.1”。
$_SER ......

【转】在Windows上配置并整合PHP和MySQL经典教程

在为用户提供动态内容方面,PHP和MySQL是一个强大的组合。这些年来,这两项产品已经跨越了它们最初的应用舞台,现在,一些世界上最繁忙的网站也在应用它们。虽然它们当初都是开源软件,只能在UNIX/Linux上运行,但经过相当一段时期的发展,它们已能在Windows平台上运行。
在本文中,我将逐步为你们说明如何在Windows环境中 ......

php常用技巧

如何判断ip地址合法性
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
 email的正则判断
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
检测ip地址和mask是否合法的例子
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号