简体   繁体   English

从电子邮件中提取客户数据

[英]Extract customer data from email

I am getting my emails through imap with php, and I get in return the message's body. 我通过使用php的imap接收电子邮件,并且得到了邮件的正文。 I need to extract some customer info from this message, like Name, E-mail, Dates and related apartment. 我需要从此消息中提取一些客户信息,例如姓名,电子邮件,日期和相关公寓。

--_av-ml1j40HUdHU5gAwKk3Xhrg
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

       --- Para responder este email, clique no botão azul abaixo ---     


Fernando, há um interessado em alugar seu imóvel!        
  COBERTURA Fantástica de FRENTE MAR! Para 6, Wifi, Ar C., Churrasq
<https://www.temporadalivre.com/conversas?id_hash=Guoqweasdd8xpu9jqlGN> 
     *Dados do Interessado*

  *Vagner Fulano*
 *vagner.spqweor01@gmail.com*

 *Período*

 21 de Dezembro de 2019 a 
26 de Dezembro de 2019
(*5 diárias*) 

 *Hóspedes*

  2 adultos, 1 criança

 *Telefone*

 44999238255

 *País*

 Brasil

 (localização por estimativa)

 *Mensagem*

 -
      Clique aqui para responder →
<https://www.temporadalivre.com/conversas?id_hash=GuoieVQACd8xpu9jqlGN>    

Above is the partial string that I can get from my emails. 上面是我可以从电子邮件中获得的部分字符串。 Or maybe, this other part can help: 也许,另一部分可以帮助您:

                    <table style="border-spacing: 0; border-collapse: collapse; vertical-align: top; text-align: left; width: 100%; padding: 0;"><tr style="vertical-align: top; text-align: left; padding: 0;" align="left"><th style="color: #0a0a0a; font-family: Helvetica, Arial, sans-serif; font-weight: normal; text-align: left; line-height: 150%; font-size: 16px; margin: 0; padding: 0;" align="left">
                         <div style="color: #daa520;">
                          <b>Dados do Interessado</b><br /></div>
                           <div style="color: #808000;">
                              <b>Vagner Splendor</b><br />
                              <span style="font-family: Helvetica, Arial, sans-serif; font-weight: normal; text-align: left; line-height: 1.3; text-decoration: none; margin: 0; padding: 0; font-size: 0.8em"><i>vagner.splendor01@gmail.com</i></span><br /><br /></div>


                           <div style="color: #daa520;"><b>Período</b><br /></div>
                          <div style="color: #808000;">21 de Dezembro de 2019 a <br>26 de Dezembro de 2019<br>(<b>5 diárias</b>) <br /><br /></div>

                           <div style="color: #daa520;"><b>Hóspedes</b><br /></div>
                          <div style="color: #808000;"> 2 adultos, 1 criança<br /><br /></div>

                           <div style="color: #daa520;"><b>Telefone</b><br /></div>
                          <div style="color: #808000;">44995528255</div><br />

                            <div style="color: #daa520;"><b>País</b><br /></div>
                            <div style="color: #808000;">Brasil<br /></div>
                            <div style="color: #808000; font-size: 14px">(localização por estimativa)<br /><br /></div>

                          <div style="color: #daa520;"><b>Mensagem</b><br /></div>
                          <div style="color: #808000;">-</div>
                        </th>
                      </tr></table></th>
                </tr></tbody></table>

Would guys have a solution for me? 伙计们对我有解决办法吗? I have no idea how I can use regex for that matter. 我不知道该如何使用正则表达式。

This is quite unstructured, and I'm positive that we might not end up with anything interesting, approaching solving this problem, if possible, maybe we should look for ways to change this problem, yet if that option is not to exercise, an example expression would be: 这是没有结构的,我很肯定我们可能不会以解决这个问题为最终目标,如果可能的话,也许我们应该寻找改变这个问题的方法,但是如果这种选择不起作用,那么这个例子表达式将是:

<i>(.+?)<\/i>|(<div style="color: #808000;">)[\s\S]*?<b>(.+?)<\/b><br

which captures the email and name using these two capturing groups, (.+?) , and the rest can be scripted. 使用这两个捕获组(.+?)捕获电子邮件和名称,其余脚本可以编写脚本。

Demo 演示版

Test 测试

$re = '/<i>(.+?)<\/i>|(<div style="color: #808000;">)[\s\S]*?<b>(.+?)<\/b><br/m';
$str = '                    <table style="border-spacing: 0; border-collapse: collapse; vertical-align: top; text-align: left; width: 100%; padding: 0;"><tr style="vertical-align: top; text-align: left; padding: 0;" align="left"><th style="color: #0a0a0a; font-family: Helvetica, Arial, sans-serif; font-weight: normal; text-align: left; line-height: 150%; font-size: 16px; margin: 0; padding: 0;" align="left">
                         <div style="color: #daa520;">
                          <b>Dados do Interessado</b><br /></div>
                           <div style="color: #808000;">
                              <b>Vagner Splendor</b><br />
                              <span style="font-family: Helvetica, Arial, sans-serif; font-weight: normal; text-align: left; line-height: 1.3; text-decoration: none; margin: 0; padding: 0; font-size: 0.8em"><i>vagner.splendor01@gmail.com</i></span><br /><br /></div>


                           <div style="color: #daa520;"><b>Período</b><br /></div>
                          <div style="color: #808000;">21 de Dezembro de 2019 a <br>26 de Dezembro de 2019<br>(<b>5 diárias</b>) <br /><br /></div>

                           <div style="color: #daa520;"><b>Hóspedes</b><br /></div>
                          <div style="color: #808000;"> 2 adultos, 1 criança<br /><br /></div>

                           <div style="color: #daa520;"><b>Telefone</b><br /></div>
                          <div style="color: #808000;">44995528255</div><br />

                            <div style="color: #daa520;"><b>País</b><br /></div>
                            <div style="color: #808000;">Brasil<br /></div>
                            <div style="color: #808000; font-size: 14px">(localização por estimativa)<br /><br /></div>

                          <div style="color: #daa520;"><b>Mensagem</b><br /></div>
                          <div style="color: #808000;">-</div>
                        </th>
                      </tr></table></th>
                </tr></tbody></table>';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM