Reputation: 448
im getting the logging times of my site, written to a textfile from the below code.
$message1 = "{\"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0#2014-09-12 04:33:38am\";}";
$timearray = explode('#', $message1, 2);
$time = strval($timearray[1]);
$file = "testtxt.txt";
$write = ($time."\n");
file_put_contents($file, $write, FILE_APPEND);
but the problem is i get the result as follows
2014-09-12 04:33:38am";}
can anybody hellp me on getting rid of
":}
in the time result
Upvotes: 0
Views: 40
Reputation: 29
Try with fallowing code, i hope this will help u out.
$message1 = "{\"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0#2014-09-12 04:33:38am\";}"; $timearray = explode('#', $message1, 2); $time1 = strval($timearray[1]); $timearray1 = explode('"',$time1, 2); $time=strval($timearray1[1]); $file = "testtxt.txt"; $write = ($time."\n"); file_put_contents($file, $write, FILE_APPEND);
Upvotes: 0
Reputation: 561
Working solution for you:
$time = str_replace('";}', '', strval($timearray[1]));
Tested it already, works.
Upvotes: 1
Reputation: 13728
cause explode index will give you result 2014-09-12 04:33:38am\";}
so need to remove it to get only time try str_replace()
$time = strval($timearray[1]);
$time = str_replace('":}','',$time);
or in one line
$write = (str_replace('":}','',$time)."\n");
Upvotes: 1