<?php
/*--------------------------------------------------------- 
 * File:conver.php
 * Author:Tomix
 * Description: 
 * Created:2009
 * -------------------------------------------------------
 * Modified history:
 * -------------------------------------------------------
 * Copyright:
 * -------------------------------------------------------
 */
 class conver
 {
 	// 将位结构的数组转化为整型值。
 	static public function arrayToInt($value)
    {
       	if(!is_array($value) || count($value) == 0)
       		return 0;
        $nReturn = 0;
        foreach ($value as $item)
        {
            if(($nReturn & $item) <= 0)
            	$nReturn += $item;
        }
        return $nReturn;
    }
    
    //将位结构的整数转化为位数组。
    static public function intToArray($value)
    {
    	if ($value <= 0)
        {
            return array(0);
        }
        else
        {
            $arr=array();
            $nLeave = $value;
            $nT = 0x01;
            while ($nLeave > 0)
            {
                if (($nLeave & 1) == 1)
                {
                    $arr[]=$nT;
                }
                $nLeave = ($nLeave >> 1);
                if ($nLeave > 0)
                {
                    $nT = ($nT << 1);
                }
            }
            return $arr;
        }
    }
 	 	 	
 	//数据库sql语句过滤函数
 	static public function toDbString($str)
 	{
 		$str=str_replace("'","&#039;",$str);	//替換單引號
// 		$str=str_replace("\"","&quot;",$str);	//替換雙引號
 		return $str;
 	}
 }
?>
