龙哥博客

WOW!这是一个技术博客耶!

  • dinamic_sidebar 3 none

  • php史上公认最安全的正反加密解密函数

    之前写过一个加解密的文章: http://www.52blogger.com/archives/387 ,也能凑合着使用, 现在为了安全, 用php写了一个triple des(3DES)的正反加解密函数. 3DES是公认的最安全的加密解密函数了,只是可惜的是php没有提供这样现成的函数,于是乎自己写了一个3DES版本的方法,3DES有很多版本,该版本采用的是ECB模式,用PKCS7补码,base64做密文,安全等级高,一般使用该函数只要修改其中的key即可.

    测试:
    echo (des3crypt( “龙哥博客”,’ENCODE’));
    echo “
    “;
    echo (des3crypt( “bxC46TETFEZFpTS1DClzpg==”,’DECODE’));
    echo “
    “;

    /**
    * 加解密函数
    * @param $str
    * @param $type
    * @param $key
    */
    function des3crypt($str,$type = ‘ENCODE’,$key = ‘AXNU7SLKJ7HKJm+x4bfBJSJQKde’){
    if(empty($str) && $str != 0){
    return false;
    }
    $td = mcrypt_module_open( MCRYPT_3DES, ”, MCRYPT_MODE_ECB, ”);
    $key = base64_decode($key);
    mcrypt_generic_init($td, $key,’12345678′);
    if(strtoupper($type) == ‘ENCODE’){
    $str = padding( $str );
    $data = mcrypt_generic($td, $str);
    }elseif(strtoupper($type) == ‘DECODE’){
    $str = base64_decode($str);
    $data = mdecrypt_generic($td, $str);
    }
    //加密
    mcrypt_generic_deinit($td);
    //结束
    mcrypt_module_close($td);
    if(strtoupper($type) == ‘ENCODE’){
    $data = removeBR(base64_encode($data));
    }elseif(strtoupper($type) == ‘DECODE’){
    $data = removePadding($data);
    }
    return $data;
    }

    //删除填充符
    function removePadding( $str ){
    $len = strlen( $str );
    $newstr = “”;
    $str = str_split($str);
    for ($i = 0; $i < $len; $i++ ){
    if (!in_array($str[$i],array(chr(0),chr(1),chr(2),chr(3),chr(4),chr(5),chr(6),chr(7),chr(8)))){
    $newstr .= $str[$i];
    }
    }
    return $newstr;
    }

    //填充密码,填充至8的倍数,pkcs7 | pkcs5
    function padding( $str ,$pkcs = 5){
    if($pkcs == 5){
    $pad = 8 – (strlen($str) % 8);
    $str .= str_repeat(chr($pad), $pad);
    }elseif($pkcs == 7){
    $len = 8 – strlen( $str ) % 8;
    for ( $i = 0; $i < $len; $i++ ){
    $str .= chr( 0 );
    }
    }
    return $str ;
    }

    /**
    * http://52blogger.com 龙哥博客版权所有,欢迎转载,转载请务必注明来源,违版必究.
    */

    //删除回车和换行
    function removeBR( $str ){
    $len = strlen( $str );
    $newstr = “”;
    $str = str_split($str);
    for ($i = 0; $i < $len; $i++ ){
    if ($str[$i] != ‘\n’ and $str[$i] != ‘\r’){
    $newstr .= $str[$i];
    }
    }
    return $newstr;
    }


  • php截取字符串函数(不打断单词)

    在项目中,遇到一个需求,如我要截取一串字符串,而又不想截取半截的单词,看了下php手册的这个mb_strimwidth() 函数,据说是不会打断单词的,可是测试没有成功,于是乎自己写个先,虽然有些小问题,但是勉强能用了,有时间再封装的好点. 该函数的实现原理是利用wordwrap()打断单词,然后用mb_strlen()计算单词的长度,截取到需要被截取的长度即可. 如下测试:

    //原字符串
    $str = ‘readonly this boolean attribute indicates that the user cannot modify the value of the control. Unlike the disabled attribute, the readonly attribute does not prevent the user from clicking or selecting in the control. long ge blog\’s The value of a read-only control is still submitted with the form.’;

    echo wordcut($str,100);

    //结果:
    readonly this boolean attribute indicates that the user cannot modify value of control. Unlike disabled attribute, …

    /**
    * 该函数截取英文字符串,不会打断英文单词,就是说不会把一个单词截取一半
    * note: 不适用于中文,当然改改也可以
    * note: 目前该函数有点小bug,$cutlength 不是指长度,而是计算所有单词的长度到了这个数时停止,其实也就是空格的长度被忽略了
    */
    function wordcut($string, $cutlength = 250, $replace = ‘…’){
    //长度不足直接返回
    if(mb_strlen($string) <= $cutlength){
    return $string;
    }else{
    //计算当前单词总长度
    $totalLength = 0;
    $datas = $newwords = array();
    //打乱文本
    $wrap = wordwrap($string,1,"\t");
    //组成数组
    $wraps = explode("\t",$wrap);

    foreach ($wraps as $tmp){
    //计算每个单词的长度
    $datas[$tmp] = mb_strlen($tmp);
    }
    foreach ($datas as $word => $length){
    //保存单词的总长度
    $totalLength += $length;
    //如果小于截取的长度则保存
    if($totalLength < $cutlength){
    array_push($newwords,$word);
    }else{
    break;
    }
    }
    //生成新字符串
    $str = trim(implode(” “,$newwords));
    return empty($str) ? $str : $str.’ ‘.$replace;
    }
    }


  • PHP POST数据的三种方法

    php有三种方法可以post数据,分别为Curl、socket、file_get_contents:

    /**
    * Socket版本
    * 使用方法:
    * $post_string = "app=socket&version=beta";
    * request_by_socket('facebook.cn','/restServer.php',$post_string);
    */
    function request_by_socket($remote_server,$remote_path,$post_string,$port = 80,$timeout = 30){
    $socket = fsockopen($remote_server,$port,$errno,$errstr,$timeout);
    if (!$socket) die("$errstr($errno)");

    fwrite($socket,"POST $remote_path HTTP/1.0\r\n");
    fwrite($socket,"User-Agent: Socket Example\r\n");
    fwrite($socket,"HOST: $remote_server\r\n");
    fwrite($socket,"Content-type: application/x-www-form-urlencoded\r\n");
    fwrite($socket,"Content-length: ".strlen($post_string)+8."\r\n");
    fwrite($socket,"Accept:*/*\r\n");
    fwrite($socket,"\r\n");
    fwrite($socket,"mypost=$post_string\r\n");
    fwrite($socket,"\r\n");

    $header = "";
    while ($str = trim(fgets($socket,4096))) {
    $header.=$str;
    }

    $data = "";
    while (!feof($socket)) {
    $data .= fgets($socket,4096);
    }

    return $data;
    }

    /**
    * Curl版本
    * 使用方法:
    * $post_string = "app=request&version=beta";
    * request_by_curl('http://facebook.cn/restServer.php',$post_string);
    */
    function request_by_curl($remote_server,$post_string){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$remote_server);
    curl_setopt($ch,CURLOPT_POSTFIELDS,'mypost='.$post_string);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_USERAGENT,"Jimmy's CURL Example beta");
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }
    /**
    * 其它版本
    * 使用方法:
    * $post_string = "app=request&version=beta";
    * request_by_other('http://facebook.cn/restServer.php',$post_string);
    */
    function request_by_other($remote_server,$post_string){
    $context = array(
    'http'=>array(
    ‘method’=>’POST’,
    ‘header’=>’Content-type: application/x-www-form-urlencoded’.”\r\n”.
    ‘User-Agent : Jimmy\’s POST Example beta’.”\r\n”.
    ‘Content-length: ‘.strlen($post_string)+8,
    ‘content’=>’mypost=’.$post_string)
    );
    $stream_context = stream_context_create($context);
    $data = file_get_contents($remote_server,FALSE,$stream_context);
    return $data;
    }

    ?>


  • cakephp 打印sql语句

    将以下语句复制到你的代码中,可以打印出在这之前所有的sql语句

    $sources = ConnectionManager::sourceList();
    if (!isset($logs)):
    $logs = array();
    foreach ($sources as $source):
    $db =& ConnectionManager::getDataSource($source);
    if (!$db->isInterfaceSupported('getLog')):
    continue;
    endif;
    $logs[$source] = $db->getLog();
    endforeach;
    endif;
    pr($logs);

  • php imap函数详解

    imap 的全名是 internet message access protocol,即网际网络信息存取协议,为美国史丹福大学 (stanford university) 在 1986 年开始研发的多重邮箱电子邮件系统。php 所提供的功能是 imap 4 的系统,这是根据 rfc 1730 所实作的。更多有关 imap 的信息可以参考 imap 的官方网站 http://www.imap.org 。

    欲使用 imap 的电子邮件功能,要先到 ftp://ftp.cac.washington.edu/imap 下载 imap 的客户端程序。在编译完成之后将 c-client/c-client.a 复制到 /usr/local/lib 之中,并将 c-client/rfc822.h、mail.h 及 linkage.h 三个文件复制到 /usr/local/include 之下。之后编译 php 程序时要加入 –with-imap 的选项。

    imap_append : 附加字符串到指定的邮箱中。
    imap_base64 : 解 base64 编码。
    imap_body : 读信的内文。
    imap_check : 返回邮箱信息。
    imap_close : 关闭 imap 链接。
    imap_createmailbox : 建立新的信箱。
    imap_delete : 标记欲删除邮件。
    imap_deletemailbox : 删除既有信箱。
    imap_expunge : 删除已标记的邮件。
    imap_fetchbody : 从信件内文取出指定部分。
    imap_fetchstructure : 获取某信件的结构信息。
    imap_header : 获取某信件的标头信息。
    imap_headers : 获取全部信件的标头信息。
    imap_listmailbox : 获取邮箱列示。
    imap_listsubscribed : 获取订阅邮箱列示。
    imap_mail_copy : 复制指定信件到它处邮箱。
    imap_mail_move : 移动指定信件到它处邮箱。
    imap_num_msg : 取得信件数。
    imap_num_recent : 取得新进信件数。
    imap_open : 打开 imap 链接。
    imap_ping : 检查 imap 是否连接。
    imap_renamemailbox : 更改邮箱名字。
    imap_reopen : 重开 imap 链接。
    imap_subscribe : 订阅邮箱。
    imap_undelete : 取消删除邮件标记。
    imap_unsubscribe : 取消订阅邮箱。
    imap_qprint : 将 qp 编码转成八位。
    imap_8bit : 将八位转成 qp 编码。
    imap_binary : 将八位转成 base64 编码。
    imap_scanmailbox : 寻找信件有无特定字符串。
    imap_mailboxmsginfo : 取得目前邮箱的信息。
    imap_rfc822_write_address : 电子邮件位址标准化。
    imap_rfc822_parse_adrlist : 解析电子邮件位址。
    imap_setflag_full : 配置信件标志。
    imap_clearflag_full : 清除信件标志。
    imap_sort : 将信件标头排序。
    imap_fetchheader : 取得原始标头。
    imap_uid : 取得信件 uid。
    imap_getmailboxes : 取得全部信件详细信息。
    imap_getsubscribed : 列出所有订阅邮箱。
    imap_msgno : 列出 uid 的连续信件。
    imap_search : 搜寻指定标准的信件。
    imap_last_error : 最后的错误信息。
    imap_errors : 所有的错误信息。
    imap_alerts : 所有的警告信息。
    imap_status : 目前的状态信息。

    imap_append
    附加字符串到指定的邮箱中。
    语法: int imap_append(int imap_stream, string mbox, string message, string [flags]);
    返回值: 整数
    函数种类: 网络系统
    内 容说明: 本函数可在指定的电子邮箱中增加附加的字符串。参数 imap_stream 为 imap 的代号。参数 mbox 为电子邮箱的位址。参数 message 为欲附加的信息。参数 flag 为可省略的标志,表示电子邮箱的标志值。治募 注意的是要与 cyrus imap 服务器沟通时,应使用 \r\n 作为行结束字符 (end-of-line, eol)。若有错误则返回 false 值。

    imap_base64
    解 base64 编码。
    语法: string imap_base64(string text);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数可将用 base64 编码字符串解码。返回值是解码后的字符串。
    参考 imap_binary() base64_encode() base64_decode()

    imap_body
    读信的内文。
    语法: string imap_body(int imap_stream, int msg_number, int [flags]);
    返回值: 字符串
    函数种类: 网络系统
    内容说明
    本函数可读取信件的内文 (body) 部份。参数 imap_stream 为 imap 的代号。参数 msg_number 为信件的序号。参数 flags 可省略,有下列的值
    ft_uid : 信件序号为 uid。
    ft_peek : 若无配置 \seen 标志则不要设本标志。
    ft_internal : 返回字符串使用系统格式,不要刻意转成 crlf 行结束标准。
    使用范例
    本例利用 imap 协议读取 myid@localhost 的第一封信件。

    imap_check
    返回邮箱信息。
    语法: object imap_check(int imap_stream);
    返回值: 类
    函数种类: 网络系统
    内容说明: 本函数可取得目前电子邮箱的信息。返回值为类类型,包含下面的属性
    date最新邮件的日期driver使用的界面mailbox电子邮箱网址nmsgs总邮件数目recent新进邮件数目
    类属性 代表意义说明
    参考 imap_mailboxmsginfo()

    imap_close
    关闭 imap 链接。
    语法: int imap_close(int imap_stream, int [flags]);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数用来关闭 imap 的资料流,亦即结束链接。可省略的参数 flags 的值若为 cl_expunge 则在关闭链接前会将电子邮件信箱清空。
    imap_createmailbox
    建立新的信箱。
    语法: int imap_createmailbox(int imap_stream, string mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明
    本函数用来建立新的信箱。成功则返回 true 值。

    imap_delete
    标记欲删除邮件。
    语法: int imap_delete(int imap_stream, int msg_number);
    返回值: 整数
    函数种类: 网络系统
    内容说明
    本函数仅用来标记欲删除之邮件。实际删除的指令 imap_expunge()

    imap_deletemailbox
    删除既有信箱。
    语法: int imap_deletemailbox(int imap_stream, string mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数用来删除既有的信箱。成功则返回 true 值。

    imap_expunge
    删除已标记的邮件。
    语法: int imap_expunge(int imap_stream);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数用来删除已加入删除标记的邮件。欲标记邮件须使用 imap_delete() 函数。

    imap_fetchbody
    从信件内文取出指定部分。
    语法: string imap_fetchbody(int imap_stream, int msg_number, string part_number, flags [flags]);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数可读取信件的内文 (body) 部份。参数 imap_stream 为 imap 的代号。参数 msg_number 为信件的序号。参数 part_number 为指定的部分。参数 flags 可省略,有下列的值
    ft_uid : 信件序号为 uid。
    ft_peek : 若无配置 \seen 标志则不要设本标志。
    ft_internal : 返回字符串使用系统格式,不要刻意转成 crlf 行结束标准。

    imap_fetchstructure
    获取某信件的结构信息。
    语法: array imap_fetchstructure(int imap_stream, int msg_number);
    返回值: 数组
    函数种类: 网络系统
    内容说明
    本函数可读取指定信件的相关信息。参数 imap_stream 为 imap 的代号。参数 msg_number 为信件的序号。返回的信息为数组的方式,各元素的内容见下表
    type 整数 (integer)encoding整数 (integer)ifsubtype布尔 (boolean)subtype字符串 (string)ifdescription布尔 (boolean)description字符串 (string)ifid布尔 (boolean)id字符串 (string)lines整数 (integer)bytes整数 (integer)ifparameters布尔 (boolean)
    元素名称 类型

    其中 type 元素的值代表的意义如下 0文字 text1复合 multipart2信息 message3程序 application4声音 audio5图形 image6影像 video7其它 other
    值 代表意义

    而 encoding 值代表的意义如下 0七位 (7 bit)1八位 (8 bit)2二进位 (binary)3base64 编码4qp 编码 (quotedprintable)5其它
    值 代表意义
    imap_header
    获取某信件的标头信息。
    语法: object imap_header(int imap_stream, int msg_number, int [fromlength], int [subjectlength], int [defaulthost]);
    返回值: 类
    函数种类: 网络系统
    内 容说明: 本函数可读取指定信件的标头信息。 msg_number 为信件的序号。返回类有下列的属性:answered、bcc、bccaddress、cc、ccaddress、date、date、deleted、 fetchfrom、fetchsubject、flagged、followup_to、from、fromaddress、in_reply_to、 maildate、message_id、msgno、newsgroups、recent、references、remail、reply_to、 reply_toaddress、return_path、return_pathaddress、sender、senderaddress、 size、subject、subject、to、toaddress、udate、unseen。

    imap_headers
    获取全部信件的标头信息。
    语法: array imap_headers(int imap_stream);
    返回值: 数组
    函数种类: 网络系统
    内容说明: 本函数可读取全部信件的标头信息。参数 imap_stream 为 imap 的代号。返回的数组一个元素为某一封信的标头。
    使用范例
    $mb = imap_open(“{my.imap.com.tw}inbox”, “wilson”, “mypasswd”);
    $allheaders = imap_headers($mb);
    imap_close($mb);
    echo ”

    \n";
    for ($i=0; $i < count($allheaders); $i++) {
    echo $allheaders[$i]."
    
    \n"; } echo "

    \n”;
    ?>

    imap_listmailbox
    获取邮箱列示。
    语法: array imap_listmailbox(int stream_id, string ref, string pattern);
    返回值: 数组
    函数种类: 网络系统
    内 容说明: 本函数可获得邮箱列示。参数 imap_stream 为 imap 的代号。参数 ref 通常为 imap 服务器名称,参考下例。参数 pattern 可用万用字符 * 代表全部的路径,aayawa@yahoo.com 并指出 (27-apr-1999) 若本参数以 “” (空字符) 代入,不会返回资料。
    使用范例
    本例为 alank@shermanloan.com 于 02-jun-1999 所提出的。
    $account = “myid”;
    $password= “mypasswd”;
    $mailbox = imap_open(“{mail.xyz.com:143}inbox”, $account, $password);
    if ($mailbox) {
    $mailboxes = imap_listmailbox($mailbox, “{mail.xyz.com:143}”, “*”);
    for ($index = 0; $index < count($mailboxes); $index++) { print($mailboxes[$index] . “\n”); } imap_close($mailbox); } else { print(“无法?/font>}启 $account 的信箱.\n”);
    }
    ?>

    imap_listsubscribed
    获取订阅邮箱列示。
    语法: array imap_listsubscribed(int stream_id, string ref, string pattern);
    返回值: 数组
    函数种类: 网络系统
    内容说明: 本函数可获得订阅邮箱 (subscribed) 列示。参数 imap_stream 为 imap 的代号。参数 ref 通常为 imap 服务器名称。参数 pattern 可用万用字符 * 代表全部的路径。
    参考 imap_listmailbox() imap_subscribe() imap_unsubscribe()

    imap_mail_copy
    复制指定信件到它处邮箱。
    语法: int imap_mail_copy(int imap_stream, string msglist, string mbox, int [flags]);
    返回值: 整数
    函数种类: 网络系统
    内 容说明: 本函数复制指定的信件到指定的邮箱 (mailbox) 之中。参数 imap_stream 为 imap 的代号。参数 msglist 可以是信件号序,也可以是范围。参数 mbox 为复制的目的邮箱。参数 flags 可省略,有二种选择 cp_uid,cp_move。

    imap_mail_move
    移动指定信件到它处邮箱。
    语法: int imap_mail_move(int imap_stream, string msglist, string mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数移动指定的信件到指定的邮箱 (mailbox) 之中。参数 imap_stream 为 imap 的代号。参数 msglist 可以是信件号序,也可以是范围。参数 mbox 为移动的目的邮箱。

    imap_num_msg
    取得信件数。
    语法: int imap_num_msg(int imap_stream);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数可取得邮箱 (mailbox) 的信件数。参数 imap_stream 为 imap 的代号。

    imap_num_recent
    取得新进信件数。
    语法: int imap_num_recent(int imap_stream);
    返回值: 整数
    函数种类: 网络系统
    内容说明
    本函数可取得邮箱 (mailbox) 的新进未读信件数。参数 imap_stream 为 imap 的代号。
    imap_open
    打开 imap 链接。
    语法: int imap_open(string mailbox, string username, string password, int [flags]);
    返回值: 整数
    函数种类: 网络系统
    内 容说明: 本函数可打开客户端与服务器之间的 imap 链接,并可链接至 pop3 或 nntp 服务器。参数 mailbox 为服务器端的位置。参数 username 为用户帐号。参数 password 为用户的密码。参数 flags 可省略,有下列的值:
    op_readonly : 打开链接使用只读状态。
    op_anonymous : 匿名读取 nntp 服务器,不使用 .newsrc 文件。
    op_halfopen : 只与 imap 或 nntp 服务器链接,不打开邮箱。
    cl_expunge : 关闭链接时自动清除邮箱中的信件。
    使用范例
    下例分别为打开 imap、pop3、nntp 的部份参考范例
    }启与 imap 服务器链接,imap 的埠 (port) 通?/font>`为 143。
    $mbox = imap_open(“{localhost/pop3:110}inbox”,”user_id”,”password”);
    \\ ?/font>}启与 pop3 服务器链接,pop3 的埠值为 110。
    $nntp = imap_open(“{localhost/nntp:119}comp.test”,”",”");
    \\ ?/font>}启与 nntp 服务器链接,nntp 的埠为 119。
    ?>

    imap_ping
    检查 imap 是否连接。
    语法: int imap_ping(int imap_stream);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函用来检查与 imap 服务器的连接状态。参数 imap_stream 为 imap 的代号。若仍然保持与 imap 服务器连接则返回 true 值。

    imap_renamemailbox
    更改邮箱名字。
    语法: int imap_renamemailbox(int imap_stream, string old_mbox, string new_mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函用来更改邮箱 (mailbox) 的名字。参数 imap_stream 为 imap 的代号。参数 old_mbox 及 new_mbox 分别为原邮箱名字及欲更换成的新邮箱名字。更换成功则返回 true 值。

    imap_reopen
    重开 imap 链接。
    语法: int imap_reopen(string imap_stream, string mailbox, string [flags]);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数可重新打开客户端与服务器之间的 imap 链接。本函数通常与 imap_ping() 函数合用。参数 mailbox 为服务器端的位置。参数 flags 可省略,有下列的值:
    op_readonly : 打开链接使用只读状态。
    op_anonymous : 匿名读取 nntp 服务器,不使用 .newsrc 文件。
    op_halfopen : 只与 imap 或 nntp 服务器链接,不打开邮箱。
    cl_expunge : 关闭链接时自动清除邮箱中的信件。
    使用范例

    imap_subscribe
    订阅邮箱。
    语法: int imap_subscribe(int imap_stream, string mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数可订阅新邮箱 (mailbox)。

    imap_undelete
    取消删除邮件标记。
    语法: int imap_undelete(int imap_stream, int msg_number);
    返回值: 整数
    函数种类: 网络系统
    内容说明
    本函数将标记欲删除邮件取消。标记欲删除邮件需使用 imap_delete()。参数 msg_number 代表邮件的流水序号。

    imap_unsubscribe
    取消订阅邮箱。
    语法: int imap_unsubscribe(int imap_stream, string mbox);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函数可取消订阅新邮箱 (mailbox)。

    imap_qprint
    将 qp 编码转成八位。
    语法: string imap_qprint(string string);
    返回值: 字符串
    函数种类: 网络系统
    内容说明
    本函数可将 qp (quoted-printable) 编码字符串转成八位字符串。
    参考 quoted_printable_decode() imap_8bit()

    imap_8bit
    将八位转成 qp 编码。
    语法: string imap_8bit(string string);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数可将八位字符串转成 qp (quoted-printable) 编码字符串。
    参考 quoted_printable_decode() imap_qprint()

    imap_binary
    将八位转成 base64 编码。
    语法: string imap_binary(string string);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数将字符串转成 mime base64 编码。此编码方式可以让中文字或者图片也能在网络上顺利传输。更多的 base64 编码信息可以参考 rfc2045 文件之 6.8 节或是 base64_encode()。
    参考 imap_base64() base64_decode() chunk_split()

    imap_scanmailbox
    寻找信件有无特定字符串。
    语法: array imap_scanmailbox(int imap_stream, string ref, string pattern, string content);
    返回值: 数组
    函数种类: 网络系统
    内 容说明: 本函用来检查与 imap 服务器信件中有无特定的字符串。参数 imap_stream 为 imap 的代号。参数 ref 通常为 imap 服务器名称,如 “{mail.wahaha.com:143}”。参数 pattern 为解析比对字符串的规则。参数 content 则为欲寻找的字符串内容。

    取得目前邮箱的信息。
    语法: object imap_mailboxmsginfo(int imap_stream);
    返回值: 类
    函数种类: 网络系统
    内 容说明: 本函用来取得目前使用中邮箱 (mailbox) 的相关信息。参数 imap_stream 为 imap 的代号。返回类包括下列的属性 date最新邮件的日期driver使用的界面mailbox电子邮箱网址nmsgs总邮件数目recent新进邮件数目unread未读邮件数目 size邮箱大小
    类属性 代表意义说明
    参考:imap_check

    imap_rfc822_write_address
    电子邮件位址标准化。
    语法: string imap_rfc822_write_address(string mailbox, string host, string personal);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数将电子邮件位址成为 rfc822 的标准格式。

    imap_rfc822_parse_adrlist
    解析电子邮件位址。
    语法: object imap_rfc822_parse_adrlist(string address, string default_host);
    返回值: 类
    函数种类: 网络系统
    内容说明: 本函数可解析电子邮件位址。返回的类包括下列属性 mailbox用户名称host服务器名称personal个人名字adl所在来源绕路
    属性名 说明
    imap_setflag_full
    配置信件标志。
    语法: int imap_setflag_full(int imap_stream, string sequence, string flag, int [options]);
    返回值: 整数
    函数种类: 网络系统
    内 容说明: 本函数可指定连续信件而配置标志。参数 imap_stream 为 imap 的代号。参数 sequence 为特定的部分序号。参数 flag 为欲配置的标志值,包括 seen、answered、flagged、deleted、draft 及 recent。参数 options 可省略,可为 st_uid。

    imap_clearflag_full
    清除信件标志。
    语法: imap_clearflag_full(int imap_stream, string sequence, string flag, int [options]);
    返回值: 无
    函数种类: 网络系统
    内 容说明: 本函数可指定连续信件而清除标志。参数 imap_stream 为 imap 的代号。参数 sequence 为特定的部分序号。参数 flag 为欲配置的标志值,包括 seen、answered、flagged、deleted、draft 及 recent。参数 options 可省略,可为 st_uid。

    imap_sort
    将信件标头排序。
    语法: array imap_sort(int imap_stream, int criteria, int reverse, int [options]);
    返回值: 数组
    函数种类: 网络系统
    内容说明
    本函数将信件标头排序。参数 imap_stream 为 imap 的代号。参数 criteria 的意义见下表,并只能是下表的其中一项 mailbox用户名称host服务器名称personal个人名字adl所在来源绕路
    属性名 说明

    参数 reverse 值为 0 时表由小到大排序,若值为 1 表由大到小排序。参数 options 可省略,有下列的值: se_uid 与 se_noprefetch。

    imap_fetchheader
    取得原始标头。
    语法: string imap_fetchheader(int imap_stream, int msg_no, int [options]);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数将信件标头排序。参数 imap_stream 为 imap 的代号。参数 msg_no 为信件序号。参数 options 可省略,其值有下列数种
    ft_uid : 信件序号为 uid。
    ft_internal : 返回字符串使用系统格式,不要刻意转成 crlf 行结束标准。
    ft_prefetchtext : 去掉额外的 rtt。

    imap_uid
    取得信件 uid。
    语法: string imap_uid(string mailbox, int msgno);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数可取得指定信件的 uid。参数 mailbox 为邮箱名。参数 msgno 为信件序号。

    imap_getmailboxes
    取得全部信件详细信息。
    语法: object imap_getmailboxes(int imap_stream, string ref, string pattern);
    返回值: 类
    函数种类: 网络系统
    内容说明: 本函用来检查 imap 服务器信件的详细信息。参数 imap_stream 为 imap 的代号。参数 ref 通常为 imap 服务器名称,如 “{mail.wahaha.com:143}”。参数 pattern 为解析比对字符串的规则。

    imap_getsubscribed
    列出所有订阅邮箱。
    语法: array imap_getsubscribed(int imap_stream, string ref, string pattern);
    返回值: 数组
    函数种类: 网络系统
    内 容说明: 本函用来列示出所有订阅 imap 服务器信箱 (mailbox)。参数 imap_stream 为 imap 的代号。参数 ref 通常为 imap 服务器名称,如 “{mail.wahaha.com:143}”。参数 pattern 为解析比对字符串的规则。

    imap_msgno
    列出 uid 的连续信件。
    语法: int imap_msgno(int imap_stream, int uid);
    返回值: 整数
    函数种类: 网络系统
    内容说明: 本函用来列示指定 uid 的连续信件。参数 imap_stream 为 imap 的代号。参数 uid 为用户代号。
    搜寻指定标准的信件。
    语法: array imap_search(int imap_stream, string criteria, int flags);
    返回值: 数组
    函数种类: 网络系统
    内 容说明: 本函用来搜寻合乎指定条件的信件。参数 imap_stream 为 imap 的代号。参数 criteria 为指定的条件,各字段以空格 (space) 分开,条件见下表。参数 flags 为 se_uid。 all返回所有合乎标准的信件answered信件有配置 \\answered 标志者bcc “字符串”bcc 栏中有指定 “字符串” 的信件before “日期”指定 “日期” 以前的信件body “字符串”内文字段中有指定 “字符串” 的信件cc “字符串”cc 栏中有指定 “字符串” 的信件deleted合乎已删除的信件flagged信件有配置 \\flagged 标志者from “字符串”from 栏中有指定 “字符串” 的信件keyword “字符串”关键字为指定 “字符串” 者new新的信件old旧的信件on “日期”指定 “日期” 的信件recent信件有配置 \\recent 标志者seen信件有配置 \\seen 标志者since “日期”指定 “日期” 之后的信件subject “字符串”subject 栏中有指定 “字符串” 的信件text “字符串”text 栏中有指定 “字符串” 的信件to “字符串”to 栏中有指定 “字符串” 的信件unanswered未回应的信件undeleted未删除的信件unflagged未配置标志的信件unkeyword “字符串”未配置关键 “字符串” 的信件unseen未读取的信件
    条件 说明

    imap_last_error
    最后的错误信息。
    语法: string imap_last_error(void);
    返回值: 字符串
    函数种类: 网络系统
    内容说明: 本函数用来显示最后出现的 imap 错误字符串。本函数不需要使用任何参数。

    imap_errors
    所有的错误信息。
    语法: array imap_errors(void);
    返回值: 数组
    函数种类: 网络系统
    内容说明: 本函数用来显示所有出现的 imap 错误字符串。本函数不需要使用任何参数。

    imap_alerts
    所有的警告信息。
    语法: array imap_alerts(void);
    返回值: 数组
    函数种类: 网络系统
    内容说明: 本函数用来显示所有出现的 imap 警告字符串。本函数不需要使用任何参数。

    imap_status
    目前的状态信息。
    语法: object imap_status(int imap_stream, string mailbox, int options);
    返回值: 类
    函数种类: 网络系统
    内 容说明: 本函数用来显示目前 imap 的状态信息。参数 imap_stream 为 imap 的代号。参数 mailbox 为指定的邮箱。参数 options 有下面的选择:sa_messages、sa_recent、sa_unseen、sa_uidnext、sa_uidvalidity 与 sa_all。


  • cakephp 与 mongodb 集成

    没有mongodb的测试环境的可以在本地安装个mongodb服务,这里有图文安装教程:

    http://www.52blogger.com/archives/786

     

    php 默认没有开启mongodb扩展,需要手动到官网上下载mongo扩展,在这里http://cn.php.net/manual/zh/mongo.installation.php#mongo.installation.windows找到适合你系统的mongo扩展,将其解压放入到php环境指定的ext目录下,同时在php.ini文件中加入

    extension=php_mongo.dll

    重启apache等服务器后生效.

     

    从github上下载cakephp与mongodb的datasouce,安装在app/plugins/目录下

     

    ps:  没有git的同志也不用担心,可以直接下载https://github.com/ichikaway/cakephp-mongodb

     

    下载完成后就可以在database.php中配置mongodb:

    var $mongo = array(
    ‘datasource’ => ‘mongodb.mongodbSource’,
    ‘database’ => ‘testmongo’,
    ‘host’ => ‘localhost’,
    ‘port’ => 27017
    );

    可以创建一个model在控制器中使用它:

    //mongb.php

    <?php
    class Mondb extends AppModel {
    var $name = ‘Mondb’;
    var $primaryKey = ‘_id’;
    var $useDbConfig = ‘mongo’;

    function schema() {
    $this->_schema = array(
    ‘_id’ => array(‘type’ => ‘integer’, ‘primary’ => true, ‘length’ => 40),
    ‘a’ => array(‘type’ => ‘string’),
    ‘b’ => array(‘type’ => ‘integer’),
    );
    return $this->_schema;
    }

    }
    ?>

    那么在控制器中就可以操作mongodb了:

    function mongo(){
    $this -> loadModel(‘Mondb’);
    $res = $this -> Mondb -> save(array(“a”=”test mongodb”,”b”=>time()));
    $res = $this -> Mondb -> find(‘all’);
    pr($res);
    exit;
    }

     

    本文地址http://www.52blogger.com/archives/793,欢迎转载,转载请注明出处.

     


  • windows 安装 mongodb服务图文教程

    准备工作:

    到官方下载合适的版本 http://www.mongodb.org/downloads

    这里用的是windows 32bit   http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip

    解压mongodb到D:\mongodb\ 目录,同时在mongodb目录中新建目录db(用于存放数据)和目录logs(存放日志),那么mongodb目录中就应该有了这些文件,如图:

     

     

     

     

    在D:\mongodb\logs\ 目录下新建一个mongodb.log 用于记录安装日志,那么都准备好了,开始安装吧~

     

    安装步骤:

    1.开始–运行–cmd

    2.cd   D:\mongodb\bin\

    3. D:\mongodb\bin>mongod –logpath D:\mongodb\logs\mongodb.log –logappend –dbpath D:\mongodb\db –directoryperdb –serviceName MongoDB –install

    如图:

     

     

     

    如果安装成功,则显示下面文字

    all output going to: D:\mongodb\logs\MongoDB.log
    Creating service MongoDB.
    Service creation successful.
    Service can be started from the command line via ‘net start “MongoDB”‘.

    安装成功后可以到windows服务中找到mongodb服务开启或者在cmd中执行命令net start MongoDB,这样mongodb服务就启动了,mongodb的默认端口是27017

    服务启动后可以执行几个简单的命令测试下:

     

     

     

     

     

     

     

     

     

     


  • 如何用php生成随机码?

    <?php

    function  makeRandomCount($length = 6){
    $key = “”;
    $str = ’0123456789ABCDEFGHIJKLOMNOPQRSTUVWXYZ’;//字符池
    for($i=0;$i<$length;$i++) {
    $key .= $str{mt_rand(0,36)};
    }
    return $key;
    }

    ?>


  • Jquery html() 与 text() 的区别

    前期天有人问我, html() 与 text() 的区别是什么??起初我也不知道,后来看了下jquery 的api,就明白了.

    先看一下jquery api上的函数说明:

    html() : 取得第一个匹配元素的html内容。这个函数不能用于XML文档。但可以用于XHTML文档。
    text() : 取得由所有匹配元素包含的文本内容组合起来的文本。这个方法对HTML和XML文档都有效。

    注意上面标记出来的关键字,仔细一看就明白了,下面来看一下简单的例子:

    <p>龙哥博客</p>

    <p>测试段落</p>

    alert($(“p”).text());

    alert($(“p”).html());

    如果你看懂了上面的代码,就很容易知道这个运行的结果了,呵呵!!


    alert($("p").text()); //结果 :龙哥博客测试段落,跟官方说的一样是所有匹配元素组合起来的文本
    alert($("p").html()); //同样的,返回的是"龙哥博客",取得第一个匹配元素中间的html代码


  • jquey文字插入光标插件,完美兼容FF 2.0+,IE6+,Chrom

    这是一款jquery的插件,主要用途是将一段文本信息插入到光标处,这个功能听起来非常简单,但实际做出来可没那么容易,主要是因为兼容性的问题,后来查阅许多资料,才发现了这款短小精悍的jquery插件,和大家分享下吧.

    (function($){
    $.fn.extend({
    insertAtCaret: function(myValue){
    var $t=$(this)[0];
    if (document.selection) {
    this.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    this.focus();
    }else if($t.selectionStart || $t.selectionStart == '0') {
    var startPos = $t.selectionStart;
    var endPos = $t.selectionEnd;
    var scrollTop = $t.scrollTop;
    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
    this.focus();
    $t.selectionStart = startPos + myValue.length;
    $t.selectionEnd = startPos + myValue.length;
    $t.scrollTop = scrollTop;
    }else{
    this.value += myValue;
    this.focus();
    }
    }
    });
    })(jQuery);

    用法:$(“select”).insertAtCaret(“text”);

    如果你不习惯这样的方式,你可以将它改为正常的函数,例如:

    function insertAtCaret(obj,myValue){
    var $t=obj[0];
    if (document.selection) {
    this.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    this.focus();
    }else if($t.selectionStart || $t.selectionStart == '0') {
    var startPos = $t.selectionStart;
    var endPos = $t.selectionEnd;
    var scrollTop = $t.scrollTop;
    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
    this.focus();
    $t.selectionStart = startPos + myValue.length;
    $t.selectionEnd = startPos + myValue.length;
    $t.scrollTop = scrollTop;
    }else{
    this.value += myValue;
    this.focus();
    }
    }

    用法和上面的类似,insertAtCaret传入一个jquery对象,以及所要插入的文本,insertAtCaret($(“select”),”text”);



  • dinamic_sidebar 4 none

©2012 龙哥博客 文章 (RSS) and 评论 (RSS) 加载博客产生 24 个查询,用时 0.356 秒