php 注意:遇到格式不正确的数值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23969488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:04:14  来源:igfitidea点击:

Notice: A non well formed numeric value encountered

phpmysqli

提问by Vipin

I have the following code and error. So please give me some suggestion how to resolve this?

我有以下代码和错误。所以请给我一些建议如何解决这个问题?

include('config/setup.php');
$query="select * from tbluser";
$fetch=mysqli_query($connect,$query) or die(mysqli_error($connect));
$row=mysqli_fetch_assoc($fetch);

echo $row['join_date']."</br>";
echo $date=strtotime($row['join_date'])."</br>";
echo $a=date('d-M-Y',$date)

2014-05-04

1399154400

Notice: A non well formed numeric value encountered in C:\xampp\htdocs\flipkart\index.php on line 12 04-May-2014

2014-05-04

1399154400

注意:2014 年 5 月 4 日第 12 行在 C:\xampp\htdocs\flipkart\index.php 中遇到格式不正确的数值

回答by Barmar

When you do:

当你这样做时:

echo $date=strtotime($row['join_date'])."</br>";

You're setting $dateto the string "1399154400</br>". date()expects its second argument to be a number, and this isn't a number because it ends with </br>.

您正在设置$date为 string "1399154400</br>"date()期望它的第二个参数是一个数字,这不是一个数字,因为它以</br>.

Change it to:

将其更改为:

$date=strtotime($row['join_date']);
echo $date . "<br/>";

or:

或者:

echo $date=strtotime($row['join_date']), "<br/>";

This sends <br/>as a separate argument to echo, rather than concatenating it when doing the assignment.

这将<br/>作为一个单独的参数发送到echo,而不是在进行赋值时连接它。

BTW, the correct tag for line breaks is <br/>, not </br>

顺便说一句,换行符的正确标记是<br/>,而不是</br>

回答by TipuZaynSultan

You are actually Passing the time with the <br />tag... So $dateis not numeric anymore. Place it directly inside the date()function...

你实际上是在用<br />标签打发时间......所以$date不再是数字了。直接放在date()函数里面...

include('config/setup.php');
$query="select * from tbluser";
$fetch=mysqli_query($connect,$query) or die(mysqli_error($connect));
$row=mysqli_fetch_assoc($fetch);

echo $row['join_date']."<br />";
echo strtotime($row['join_date'])."<br />";
echo date('d-M-Y', strtotime($row['join_date']));