从php获取错误我做错了什么?
所以我得到了下面的错误 [02-11-2015 16:29:48美国/洛杉矶]PHP警告: number_format()要求参数1为双精度,字符串以 第17行的C:\inetpub\wwwroot\handpaytest\index.php 这就是它抱怨的代码从php获取错误我做错了什么?,php,Php,所以我得到了下面的错误 [02-11-2015 16:29:48美国/洛杉矶]PHP警告: number_format()要求参数1为双精度,字符串以 第17行的C:\inetpub\wwwroot\handpaytest\index.php 这就是它抱怨的代码 echo "<td>Past Week: $" . number_format(htmlspecialchars($cell)) . "</td>"; echo“过去一周:$”。数字\u格式(htmlspe
echo "<td>Past Week: $" . number_format(htmlspecialchars($cell)) . "</td>";
echo“过去一周:$”。数字\u格式(htmlspecialchars($cell))。"";
在上下文中
<div id='Title'></div>
<div id='week'>
<?php
echo "<center><table>\n\n";
$f = fopen("week.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>Past Week: $" . number_format(htmlspecialchars($cell)) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n</center></table>";
?>
</div>
由于我们不知道$cell包含什么,您可以尝试将其类型强制为float
echo "<td>Past Week: $" . number_format((float)$cell)) . "</td>";
echo“过去一周:$”。数字_格式((浮点)$cell))。"";
什么是将特殊字符转换为HTML实体
因此,在将其传递给之前,您需要将$cell作为(float)$cell
正如Dagon在上面所说^,什么是
$cell
?用谷歌搜索你的错误;很多点击。$cell只包含一个从csv文件中获取的数值。谢谢这就是诀窍。
number_format((float)$cell)