使用php从文件中删除时间戳

时间:2014-11-05 05:25:12

标签: php json timestamp

我需要使用php从[04-Nov-2014 12:22:17 UTC]中删除时间戳error_log。时间戳出现在开头和EOF,文件没有任何换行符。 error_log看起来有点像这样。它采用JSON格式。

[04-Nov-2014 12:22:17 UTC]{"buyer_accepts_marketing":false,"cart_token":"eeafa272cebfd4b22385bc4b645e762c","closed_at":null,"completed_at":null,"created_at":null,"currency":null,"email":"","gateway":null,"id":327474488104976385,"landing_site":null,"note":null,"referring_site":null,"shipping_lines":

我已尝试过preg_match()array_shift()等。但它们都没有提供令人满意的输出。

在php中执行此操作的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

尝试使用此pre_replace();

$string =   '[04-Nov-2014 12:22:17 UTC]{"buyer_accepts_marketing":false,"cart_token":"eeafa272cebfd4b22385bc4b645e762c","closed_at":null,"completed_at":null,"created_at":null,"currency":null,"email":"","gateway":null,"id":327474488104976385,"landing_site":null,"note":null,"referring_site":null,"shipping_lines":';

echo preg_replace('/\[([0-9\-a-zA-Z]{1,}) ([0-9\:]{1,}) ([0-9\a-zA-Z]{1,})\]/',"",$string);