将print_r输出插入MySQL


Insert print_r output into MySQL

我在远程服务器的文本文件(dump.log)中有这个输出。我不能访问php创建的原始数组:

Array
(
    [email] => ddiar@beu.ac.il
    [timestamp] => 1369735202
    [smtp-id] => <1369735199.51as4801fed0f7@www.pub.org>
    [category] =>  decision 
    [event] => processed
)
Array
(
    [email] => jc@open.com
    [timestamp] => 1369735202
    [smtp-id] => <1369735199.51a4801fed0f7@www.open.org>
    [category] => Interm 
    [event] => processed
)
Array
(
    [email] => ilgkliar@bku.ac.il
    [timestamp] => 1369735204
    [smtp-id] => <1369735199.51ahg4801fed0f7@www.open.org>
    [response] => 250 OK: <ed628ghjbf2000aec70@bkju.ac.il> 
    [category] => decision 
    [event] => delivered
)

现在我想使用PHP将值插入MySQL表。(如email_field, time_field,category_field..))

我尝试函数print_r_reverse从这里,但没有运气。请提供完整代码

需要使用print_r吗?对于您的目的,var_export更适合。

http://www.php.net/manual/en/function.var-export.php

输出或返回变量的可解析字符串表示形式

我可能会使用json_encodejson_decode

先检查你的PHP是否支持JSON

您有几个选择:

  • 使用sedawk将数据提取成CSV文件,然后可以使用LOAD DATA LOCAL
  • 导入数据库
  • 编写PHP代码,将采取每一行,寻找每一行的特定功能,然后创建一个数组,可以导入到数据库中使用任何PHP MySQL命令你喜欢(但不是mysql_的,因为他们已弃用)
  • 花钱请人帮你写代码

无论哪种方式,我猜都会涉及到正则表达式。

如果你想让别人帮你写代码,那么你就来错地方了。