Crumor Posted June 4, 2014 Share Posted June 4, 2014 (edited) Warning: implode() [function.implode]: Invalid arguments passed in /home/content/59/11840059/html/ViatixElectro/includes/funciones.php on line 169 this is the line in funciones.php: $value = implode($locale['mon_decimal_point'], $value); this is the whole code: function money_formats($format, $number) { $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'. '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/'; if (setlocale(LC_MONETARY, 0) == 'C') { setlocale(LC_MONETARY, ''); } $locale = localeconv(); preg_match_all($regex, $format, $matches, PREG_SET_ORDER); foreach ($matches as $fmatch) { $value = floatval($number); $flags = array( 'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ', 'nogroup' => preg_match('/\^/', $fmatch[1]) > 0, 'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+', 'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0, 'isleft' => preg_match('/\-/', $fmatch[1]) > 0 ); $width = trim($fmatch[2]) ? (int)$fmatch[2] : 0; $left = trim($fmatch[3]) ? (int)$fmatch[3] : 0; $right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; $conversion = $fmatch[5]; $positive = true; if ($value < 0) { $positive = false; $value *= -1; } $letter = $positive ? 'p' : 'n'; $prefix = $suffix = $cprefix = $csuffix = $signal = ''; $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; switch (true) { case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+': $prefix = $signal; break; case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+': $suffix = $signal; break; case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+': $cprefix = $signal; break; case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+': $csuffix = $signal; break; case $flags['usesignal'] == '(': case $locale["{$letter}_sign_posn"] == 0: $prefix = '('; $suffix = ')'; break; } if (!$flags['nosimbol']) { $currency = $cprefix . ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix; } else { $currency = ''; } $space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; $value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']); $value = @explode($locale['mon_decimal_point'], $value); $n = strlen($prefix) + strlen($currency) + strlen($value[0]); if ($left > 0 && $left > $n) { $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0]; } $value = implode($locale['mon_decimal_point'], $value); if ($locale["{$letter}_cs_precedes"]) { $value = $prefix . $currency . $space . $value . $suffix; } else { $value = $prefix . $value . $space . $currency . $suffix; } if ($width > 0) { $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT); } $format = str_replace($fmatch[0], $value, $format); } return $format; } Edited June 4, 2014 by requinix please use [code] tags when posting code Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/ Share on other sites More sharing options...
dalecosp Posted June 4, 2014 Share Posted June 4, 2014 What is in $locale ? //debug print_r($locale);exit; if $locale['mon_decimal_point'] is set correctly, then $value must be null ... that's a bigger problem than a simple implode() call.... Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/#findComment-1481885 Share on other sites More sharing options...
Crumor Posted June 4, 2014 Author Share Posted June 4, 2014 $locale returns an associative array containing information of numeric and monetary formats, the code is not mine, but throws me this error. Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/#findComment-1481894 Share on other sites More sharing options...
Jacques1 Posted June 4, 2014 Share Posted June 4, 2014 We could speculate all day long about what might be the problem. But it makes much more sense to actually investigate it. So if the arguments are not valid, what exactly are they? var_dump() will help you find out. Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/#findComment-1481897 Share on other sites More sharing options...
mogosselin Posted June 5, 2014 Share Posted June 5, 2014 (edited) Here's the manual for the implode function: http://www.php.net/manual/en/function.implode.php It says: string implode ( string $glue , array $pieces ) The first "string" means that it will return a string. The string $glue means that the first parameter should be a string. The array $pieces means that the second parameter should be an array. If you get that error: Warning: implode() [function.implode]: Invalid arguments passed in It means that one of those 2 arguments (the $glue or $pieces) is incorrect. Or both. To know which one is incorrect, you should output them and see what they contain (just before calling the function). var_dump($glue); var_dump($pieces); When you "var_dump" a variable, it will also give you the type of the variable. So if $glue is not a string, that's a problem. if $pieces is not an array, that's a problem too. Edited June 5, 2014 by mogosselin Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/#findComment-1481910 Share on other sites More sharing options...
Maq Posted June 6, 2014 Share Posted June 6, 2014 Side note: When developing you should have error reporting on and remove '@' symbols from your code (which suppress error messages): $value = @explode($locale['mon_decimal_point'], $value); Quote Link to comment https://forums.phpfreaks.com/topic/288985-help-with-this-error-pls/#findComment-1482070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.