Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分离电子邮件内容并转换为MYSQL数据PHP_Php_Mysql - Fatal编程技术网

分离电子邮件内容并转换为MYSQL数据PHP

分离电子邮件内容并转换为MYSQL数据PHP,php,mysql,Php,Mysql,以下是一个例子: Customer: Bob Smith Account: 1234 Address: 123 Main St City: Anywhere, USA 我想将其转换为一个MYSQL表,其中包含Customer、Account、Address和City列 我不是实现这一点的最佳方法。您可以这样解析您的文本: $str = "Customer: Bob Smith Account: 1234 Address: 123 Main St City: Anywhere, USA"; p

以下是一个例子:

Customer: Bob Smith 
Account: 1234
Address: 123 Main St
City: Anywhere, USA
我想将其转换为一个MYSQL表,其中包含Customer、Account、Address和City列


我不是实现这一点的最佳方法。

您可以这样解析您的文本:

$str = "Customer: Bob Smith Account: 1234 Address: 123 Main St City: Anywhere, USA";
preg_match("/Customer\\:(.*)Account\\:(.*)Address\\:(.*)City\\:(.*)/",$str,$matches);
$customer = $matches[1];
$account = $matches[2];
$address = $matches[3];
$city= $matches[4];

经过这个过程。您可以轻松发送到mysql:)

是否通过表单提交自动发送电子邮件?您是否控制发送它们的脚本?如果不是,您能相信内容的格式是一致的吗?它们不是来自表单提交。我不控制它们的发送方式,但它处于受控环境中。这些电子邮件是从服务器自动生成的,格式不会改变。有大约一百万种方法可以做到这一点,从抓取到简单地将文本分解成一个数组。您需要的是一个带有插入代码的数据库布局,您没有付出任何努力。谢谢您的帮助。这基本上就是我想要的。有没有关于删除实际电子邮件的想法?我一直在研究imap_fetchbody来实现这一点