Jump to content

[SOLVED] A non well formed numeric value encountered


EP

Recommended Posts

Hello, I need a little help here.  I can't figure out what seems to be the problem with my code here.  Everytime my script executes, I get a log full of this type stuff over and over again:

 

[sat May 30 07:23:36 2009] [error] [client 127.0.0.1] PHP Notice:  A non well formed numeric value encountered in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\topsongs.php on line 234

 

Here is an example of the code I am having a problem with:

 


$now = date('Y-m-d H:i:s');
$now2 = strtotime($now);
$oneweek = strtotime("+1 week", $now);
$oneweekago = $now2-$oneweek;

$timeplayedaddstr = strtotime($timeplayedadd);


if($timeplayedaddstr>$oneweekago){
$topsongs[$arraytitle]['playsthisweek'] = $topsongs[$arraytitle]['playsthisweek'] + 1;
};


 

Hopefully that's enough code to give you an idea of what I am trying to do.

 

$timeplayedadd is a variable which is defined in each entry in my array.  It is time and date of the entry in the default mysql format.

 

The line that generates the "non well formed numeric value" error in the log is:

 

$oneweek = strtotime("+1 week", $now);

 

Any idea of how to fix this?

 

Link to comment
Share on other sites

I tried that already, it's not working for me.

 

 

Here, try this:

 

<?php

$now = date('Y-m-d H:i:s');
$now2 = strtotime($now);
$oneweek = strtotime("+1 week",$now);
$oneweek2 = strtotime("+1 week");
$oneweekago = $now2-$oneweek;
$oneweekagosearch = date('Y-m-d H:i:s',$oneweekago);

echo "now: " . $now . "<BR>\n";
echo "now2: " . $now2 . "<BR>\n";
echo "oneweek: " . $oneweek . "<BR>\n";
echo "oneweek2: " . $oneweek2 . "<BR>\n";
echo "oneweekago: " . $oneweekago . "<BR>\n";
echo "oneweekagosearch: " . $oneweekagosearch . "<BR>\n";

?>

 

Here's the output I got from that:

 

now: 2009-05-30 08:25:23
now2: 1243697123
oneweek: 606809
oneweek2: 1244301923
oneweekago: 1243090314
oneweekagosearch: 2009-05-23 07:51:54

 

And I still got a line in the error.log that says "A non well formed numeric value encountered"

 

I need the output from the $oneweek line to be a certain way or it throws the rest of the script off.  Maybe there is something else I can use for that line besides strtotime?

Link to comment
Share on other sites

You still get the error because you didn't follow my advice. And I don't think you need all those values? To get the timestamp from one week ago:

 

$oneweekago = strtotime('-1 week');

Your current code may work because strtotime() defaults to using the Unix Epoch (timestamp 0) when you feed it a wrongful second parameter.

Link to comment
Share on other sites

Ok, I got it to work.

 


<?php

$oneweek = date('Y-m-d H:i:s', strtotime('-1 week'));
$oneweekago = strtotime($oneweek);

echo "oneweek: " . $oneweek . "<BR>\n";
echo "oneweekago: " . $oneweekago . "<BR>\n";


?>

 

Works just fine.

 

Thanks for the help. :D

Link to comment
Share on other sites

You're welcome :)

 

I guess you could improve your naming of the variables to make it easier for everyone; e.g.

 

<?php
$lastweek_timestamp = strtotime('-1 week');
$lastweek_str = date('Y-m-d H:i:s', $lastweek_timestamp);
?>

As you can see, I also reused the timestamp instead of running strtotime() twice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.