EP Posted May 30, 2009 Share Posted May 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/ Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 strtotime() expects a integer as second parameter; you're prodiving a string ($now). You can simply omit the second parameter, since you're using the current timestamp: $oneweek = strtotime("+1 week"); Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/#findComment-845800 Share on other sites More sharing options...
EP Posted May 30, 2009 Author Share Posted May 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/#findComment-845804 Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/#findComment-845809 Share on other sites More sharing options...
EP Posted May 30, 2009 Author Share Posted May 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/#findComment-845823 Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160271-solved-a-non-well-formed-numeric-value-encountered/#findComment-845835 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.