易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 :

php常用函数2

文件读取函式
   //文件读取函式
   function PHP_Read($file_name) {
   $fd=fopen($file_name,r);
   while($bufline=fgets($fd, 4096)){
   $buf.=$bufline;
    }
   fclose($fd);
   return $buf;
    }
   ?>
文件写入函式
    //文件写入函式
   function PHP_Write($file_name,$data,$method="w") {
   $filenum=@fopen($file_name,$method);
   flock($filenum,LOCK_EX);
   $file_data=fwrite($filenum,$data);
   fclose($filenum);
   return $file_data;
    }
   ?>
静态页面生成函式
   //静态页面生成函式
   function phptohtm($filefrom,$fileto,$u2u=1){
   if($u2u==1){
   $data=PHP_Read($filefrom);
    }else{
   $data=$filefrom;
    }
   PHP_Write($fileto,$data);
   return true;
& ......

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 = ip2long($ip);
$mask = ip2long($mask);
$network = ip2long($network);
if( ($ip & $mask) == $network) echo "valid ip and maskn";
?>
文件下载头部输出如何设定
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo 'xxx'
用header输出ftp下载方式,并且支持断点续传
一个例子:
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Accept-Ranges: bytes');
header('Connection: close');
header("Content-Type: audio/mpeg");
header("Location:ftp://download:1bk3l4s3k9s2@232.2.2 ......

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处理后插如数据库,然后使用此函数会让代码执行
  */
 fun ......

PHP网页导出Word文档的方法

原理
    一般,有2种方法可以导出doc文档,一种是使用com,并且作为php的一个扩展库安装到服务器上,然后创建一个com,调用它的方法。安装过office的服务器可以调用一个叫word.application的com,可以生成word文档,不过这种方式我不推荐,因为执行效率比较低(我测试了一下,在执行代码的时候,服务器会真的去打开一个word客户端)。理想的com应该是没有界面的,在后台进行数据转换,这样效果会比较好,但是这些扩展一般需要收费。
    第2种方法,就是用PHP将我们的doc文档内容直接写入一个后缀为doc的文件中即可。使用这种方法不需要依赖第三方扩展,而且执行效率较高。
    word本身的功能还是很强大的,它可以打开html格式的文件,并且能够保留格式,即使后缀为doc,它也能识别正常打开。这就为我们提供了方便。但是有一个问题,html格式的文件中的图片只有一个地址,真正的图片是保存在其他地方的,也就是说,如果将HTML格式写入doc中,那么doc中将不能包含图片。那我们如何创建包含图片的doc文档呢?我们可以使用和html很接近的mht格式。
    mht格式和html很类似,只不过在mht格式中,外部链接进来 ......

PHP中strtr和str_replace比较

首先这2个函数都是具有替换字符功能的。但是strtr比str_replace性能上要块4倍。具体情况请看如下分解:
首先是strtr函数:
实例1:当
以下为引用的内容:
<?php
//这个时候输出的为baicai而不是bai123cai,因为str("pao")<strlen("bai123")
echo strtr("paocai!","pao","bai123");
?>
实例2:当被替换的值长度小于被替换目标的时候
以下为引用的内容:
<?php
//这个时候输出的为laocai而不是lacai,因为str("pao")>strlen("la")
 
echo strtr("paocai!","pao","la");
 
?>
实例3:支持数组替换
以下为引用的内容:
<?php
$Arr=array('ao'=>'oa','ai'=>'ia');
echo strtr("paocai!",$Arr); //这个时候输出的为poacia
?>
其次是str_replace:
以下为引用的内容:
<?php
echo str_replace("you","paocai","I love you!"); //会输出I love paocai!
?>
总结:strtr他是跟字符长度有关系的,但是str_replace就没有关系,估计在运行步骤的时候会读取字符串长度所以才会比strtr慢很多。 ......

php中pack与unpack

pack/unpack的摸板字符字符含义
format 参数的可能值:
a - NUL-padded string
A - SPACE-padded string
h - Hex string, low nibble first
H - Hex string, high nibble first
c - signed char
C - unsigned char
s - signed short (always 16 bit, machine byte order)
S - unsigned short (always 16 bit, machine byte order)
n - unsigned short (always 16 bit, big endian byte order)
v - unsigned short (always 16 bit, little endian byte order)
i - signed integer (machine dependent size and byte order)
I - unsigned integer (machine dependent size and byte order)
l - signed long (always 32 bit, machine byte order)
L - unsigned long (always 32 bit, machine byte order)
N - unsigned long (always 32 bit, big endian byte order)
V - unsigned long (always 32 bit, little endian byte order)
f - float (machine dependent size and representation)
d - double (machine dependent size and representation)
x - NUL byte
X - Back up one byte
@ - NUL-fill to absolute position
a一个填充� ......
总记录数:40319; 总页数:6720; 每页6 条; 首页 上一页 [5900] [5901] [5902] [5903] 5904 [5905] [5906] [5907] [5908] [5909]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号