2015-01-15 91 views
-4

我收到以下错误:警告:number_format()预计参数1双待,串给出

Warning: number_format() expects parameter 1 to be double, string given in............. on line 200

请告诉我它的解决方案。下面我贴我的整个代码直到行200

<?php 
function my_session_start() { 
    session_start(); 
} 

function escape($str) { 
    $clean_str = (get_magic_quotes_gpc()) ? mysql_real_escape_string(stripslashes(trim($str))) : mysql_real_escape_string(trim($str)); 
    return $clean_str; 
} 

function _addslashes($str) { 
    $clean_str = (get_magic_quotes_gpc()) ? $str : addslashes($str); 
    return $clean_str; 
} 

function clean($str) { 
    $clean_str = stripslashes (trim($str)); 
    return $clean_str; 
} 

function checkbox_value($str) { 
    if(isset($_POST[$str]) && $_POST[$str]=="on") return 1; 
    return 0;  
} 

function generate_random() { 
    $str = md5(uniqid(rand(),1)); 
    return $str; 
} 

function html_link($str) { 
    $str=correct_href($str); 
    $ret='<a href="'.$str.'">'.$str.'</a>'; 
    return $ret; 
} 

function correct_href($str) { 
    if(!trim($str)) return; 
    if(strcmp(substr($str,0,7),"http://") && strcmp(substr($str,0,8),"https://")) $str="http://".$str; 
    return $str; 
} 

function correct_number_format($str) { 
    $app = new appearance(); 
    $appearance = $app->getAll(); 
    $decimals = $appearance['number_format_decimals']; 
    $point = $appearance['number_format_point']; 
    $separator = $appearance['number_format_separator']; 
    $ereg_str = "/^[0-9]*".$point."*[0-9]+".$separator."*[0-9]*$/"; 
    $ereg_str = str_replace(".", "\.", $ereg_str); 
    if(preg_match($ereg_str, $str)) return 1; 
    return 0;  
} 

function correct_numeric($str) { 
    global $appearance_settings; 
    $point = $appearance_settings['number_format_point']; 
    $separator = $appearance_settings['number_format_separator']; 
    // replace 
    $str = str_replace($point,"#",$str); 
    $str = str_replace($separator,"",$str); 
    $str = str_replace("#",".",$str); 
    return $str; 
} 

function correct_price($str) { 
    global $appearance_settings; 
    $point = $appearance_settings['price_format_point']; 
    $separator = $appearance_settings['price_format_separator']; 
    // replace 
    $str = str_replace($point,"#",$str); 
    $str = str_replace($separator,"",$str); 
    $str = str_replace("#",".",$str); 
    return $str;  
} 
+1

什么是您发布的代码的第200行?除了自定义函数外,我在代码中的任何地方都看不到'number_format()'......? – 2015-01-15 15:37:03

+2

我看到太多这样的问题。花时间学习如何[解释错误并修复代码](http://jason.pureconcepts.net/2013/05/fixing-php-errors/)。 – 2015-01-15 15:37:33

+0

其空行。请告诉我解决方案,将其删除。我会很高兴。谢谢 – Ali 2015-01-15 15:38:17

回答

2

在任一format_price($ STR)或format_int($ STR),其中这是发生我会做如下修改:

$result = number_format($str, $decimals, $point, $th_separator); 

$result = number_format((int)$str, $decimals, $point, $th_separator); 

如果号码包含便士使用

$result = number_format((float)$str, $decimals, $point, $th_separator); 
相关问题