"08/01/2013", "StartTi...">

Why does sprintf give asterisks instead of my formatted string?

This code:

function atest(){ $test = array( "StartDate" => "08/01/2013", "StartTime" =>"08:00:00", "DepartmentID" => "75275", "# Contacts Offered" => "3", "# Contacts Handled" => "4", "Average Talk Time" => "491.250000", "Average Delay" => "5.666667", "Percent SLA" => "1.333333"); $formatted = sprintf("%s %s TCSDATA %d %d %d %01.2f 0 %01.2f %01.2f 0\r\n", $test["StartDate"], $test["StartTime"], $test['DepartmentID'], $test['# Contacts Offered'], $test['# Contacts Handled'], $test['Average Talk Time'], $test['Average Delay'], $test['Percent SLA'] ); echo('<pre>'); echo( var_dump($test) ); echo('</pre>'); echo $formatted; } 

Will print this:

 08/01/2013 08:00:00 TCSDATA 75275 ************************ 

However, if I change the sprintf format to remove the last 0 as such:

 "%s %s TCSDATA %d %d %d %01.2f 0 %01.2f %01.2f \r\n" 

I get this:

 08/01/2013 08:00:00 TCSDATA 75275 3 4 491.25 0 5.67 1.33 

What in the world?

+4
source share
2 answers

This problem was actually caused by the fact that the sequence of numbers corresponded to the Moon algorithm and was masked in my PCI environment. I manually excluded the file from the test, and now everything works as expected.

+2
source

Even PHP 5.3.20 (cli) (built: December 20, 2012 06:20:32) cannot reproduce this error, so updating to 5.4 might not be necessary.

0
source

Source: https://habr.com/ru/post/1495059/


All Articles