so I’ve made a clock-time to seconds function, and it works fine when running on it’s on, with the test string…say 12:53:13 PM.
But when I put it in another script (via require, or just copy-pasting) I’m finding a problem, I’m not sure if it’s specifically due to the function, but this is just weird. The string
“PM” is registering as 6 characters instead of 2 like it should, is what a var_dump says. Any ideas why?
I got the time by exploding an imploding a string of the entire date. This is actually the code
$time = explode(" ",$dateallstr);
$time = array($time[5],$time[6]);
$time = implode(" ",$time);
var_dump($time);
//require("timeinsecs.php");
And this is what var_dump returns
array(4) { [0]=> string(2) "11" [1]=> string(2) "14" [2]=> string(2) "55" [3]=> string(6) "PM" }
This is the starting string.
DATEALLSTR: string(45) "Tuesday 14th of February 2012 11:14:55 PM"
Please help, I have no clue why it would do this.
EDIT:
Ok, got the bin2hex. I’m not sure if this whole thing is just the bin2hex.
BIN2HEX504d3c2f693estring(6) “PM”
The original string has length 41. It looks like somehow your input carries 4 NUL characters after the text which are not printed but do count to the length:
You can try to
trim()the input beforeexplode(), that should get rid of the extra characters:Edit: You’ve skipped the first step of troubleshooting in PHP: viewing the source to see what the web browser doesn’t show. Now that you have posted the hex dump, we see that the last string is actually
"PM</i>".