示例#1
0
/**
 * 格式化商品价格
 *
 * @access  public
 * @param   float   $price  商品价格
 * @return  string
 */
function price_format($price, $change_price = true,$visibal=true)
{
    if ($change_price && defined('ECS_ADMIN') === false)
    {
        switch ($GLOBALS['_CFG']['price_format'])
        {
            case 0:
                $price = number_format($price, 2, '.', '');
                break;
            case 1: // 保留不为 0 的尾数
                $price = preg_replace('/(.*)(\\.)([0-9]*?)0+$/', '\1\2\3', number_format($price, 2, '.', ''));

                if (substr($price, -1) == '.')
                {
                    $price = substr($price, 0, -1);
                }
                break;
            case 2: // 不四舍五入,保留1位
                $price = substr(number_format($price, 2, '.', ''), 0, -1);
                break;
            case 3: // 直接取整
                $price = intval($price);
                break;
            case 4: // 四舍五入,保留 1 位
                $price = number_format($price, 1, '.', '');
                break;
            case 5: // 先四舍五入,不保留小数
                $price = round($price);
                break;
        }
    }
    else
    {
        $price = number_format($price, 2, '.', '');
    }
	$format = $GLOBALS['_CFG']['currency_format'];
	$str = preg_match('/^%/',$format,$str);
	if($str){
		if(EC_CHARSET == 'utf-8'){
			$str = sprintf(rpcLang("goods.php",'currency_format'),$price);
			if(isgbk($str)){
				$str = iconv('utf-8', "gbk",$str);
			}
			return $str;
		}else{
			return sprintf(rpcLang("goods.php",'currency_format'),$price);
		}
	}else{
		if(EC_CHARSET == 'utf-8'){
			$str = sprintf($GLOBALS['_CFG']['currency_format'], $price);
			if(isgbk($str) && $visibal == true){
				$str = iconv('utf-8', "gbk",$str);
			}
			return $str;
		}else{
			return sprintf($GLOBALS['_CFG']['currency_format'], $price);
		}
	}
}
示例#2
0
文件: lib_main.php 项目: noikiy/mdwp
/**
 *
 * @todo  对字符串或数组进行本地化编码
 * @param array or string  
 * @return string 
 *	
 */
function utf8togbk($data)
{
	if(is_array($data))
	{
		foreach($data as &$value)
		{
			$value = utf8togbk($value);
		}
	}
	else
	{
		//if(EC_CHARSET != 'utf-8'){
		if(!isgbk($data))
		{
			$data = iconv("utf-8", 'gbk',$data);
		}
	}
	return $data;
}