Prog_Rookie
Prog_Rookie

Reputation: 448

editing the php variable

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

Answers (3)

Mahesh Yallure
Mahesh Yallure

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

Lauri Orgla
Lauri Orgla

Reputation: 561

Working solution for you:

$time      = str_replace('";}', '', strval($timearray[1]));

Tested it already, works.

Upvotes: 1

Rakesh Sharma
Rakesh Sharma

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

Related Questions