从csv文件中获取特定数据

时间:2014-08-06 22:25:55

标签: php regex csv

我有一个csv文件,我只想检索以下字段:

mobile=0786066486&phone_num=&mob_phone_num=6066486

作为示例我的文件如何:

LeadID,ClientID,res,Name,Phone,Email,Serial,Time,Comment,Address,wasSent,Promocode,custDetails,DynamicSerialParams
7276199,B6FBEEBF-FE33-42D3-B0B8-83BF44F3C192,NULL,محمد ابوالرب,-786065524,king_moneer45@yahoo.com,339863,30/06/2014 00:00,<additional><pageName type='text'>masterLP - overnight96NDH5</pageName><FName type='text'>محمد</FName><LName type='text'>ابوالرب</LName><Mobile type='text'>0786066486</Mobile><Country type='text'>Jordan</Country><SendEmails>true</SendEmails><IP>91.186.228.92</IP><CountryID>107</CountryID><Language>Arabic</Language><source>zomztest</source></additional>,Jordan,1,b3b9ffe9-9301-4bd2-932f-cfab2f0f61d1,<OperatingSystem>Windows NT 6.1</OperatingSystem><UserLang>ar</UserLang><Browser>Chrome</Browser><BrowserVersion>Chrome 35.0.1916.153</BrowserVersion><Refferer>http://www.zomztest.ae/landing_pages/br1/ar/overnight96NDH5/?content=overnight96NDH5&dsp9=uae-t.com&dsp8=البورصة&dsp1=&SID=339863&gclid=CNmkp5KloL8CFcbKtAodk3gAag</Refferer><Url>http://l.zomztest.com/lead.ashx?fname=محمد&lname=ابوالرب&country=JO&email=king_moneer45@yahoo.com&phone=0786066486&sendmails=true&mobile=0786066486&phone_num=&mob_phone_num=6066486&area_code=&mob_area_code=078&cat=masterLP&promocode=&SID=339863&clang=AE&content=overnight96NDH5&gclid=CNmkp5KloL8CFcbKtAodk3gAag&dsp8=%D8%A7%D9%84%D8%A8%D9%88%D8%B1%D8%B5%D8%A9&dsp9=uae-t.com</Url><IP>91.186.228.92</IP>,dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=البورصة&dsp9=uae-t.com&dsp10=&dsp11=&dsp12=&dsp13=&dsp14=&dsp15=
7276199,B6FBEEBF-FE33-42D3-B0B8-83BF44F3C192,NULL,محمد ابوالرب,-786065524,king_moneer45@yahoo.com,339863,30/06/2014 00:00,<additional><pageName type='text'>masterLP - overnight96NDH5</pageName><FName type='text'>محمد</FName><LName type='text'>ابوالرب</LName><Mobile type='text'>0786066486</Mobile><Country type='text'>Jordan</Country><SendEmails>true</SendEmails><IP>91.186.228.92</IP><CountryID>107</CountryID><Language>Arabic</Language><source>zomztest</source></additional>,Jordan,1,b3b9ffe9-9301-4bd2-932f-cfab2f0f61d1,<OperatingSystem>Windows NT 6.1</OperatingSystem><UserLang>ar</UserLang><Browser>Chrome</Browser><BrowserVersion>Chrome 35.0.1916.153</BrowserVersion><Refferer>http://www.zomztest.ae/landing_pages/br1/ar/overnight96NDH5/?content=overnight96NDH5&dsp9=uae-t.com&dsp8=البورصة&dsp1=&SID=339863&gclid=CNmkp5KloL8CFcbKtAodk3gAag</Refferer><Url>http://l.zomztest.com/lead.ashx?fname=محمد&lname=ابوالرب&country=JO&email=king_moneer45@yahoo.com&phone=0786066486&sendmails=true&mobile=0786066486&phone_num=&mob_phone_num=6066486&area_code=&mob_area_code=078&cat=masterLP&promocode=&SID=339863&clang=AE&content=overnight96NDH5&gclid=CNmkp5KloL8CFcbKtAodk3gAag&dsp8=%D8%A7%D9%84%D8%A8%D9%88%D8%B1%D8%B5%D8%A9&dsp9=uae-t.com</Url><IP>91.186.228.92</IP>,dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=البورصة&dsp9=uae-t.com&dsp10=&dsp11=&dsp12=&dsp13=&dsp14=&dsp15=
7276200,B6FBEEBF-FE33-42D3-B0B8-83BF44F3C192,NULL,jose miguel abad tirado,-73501424,marjos091111@hotmail.com,236455,30/06/2014 00:01,<additional><pageName type='text'>masterLP - Testimonials5NoTime</pageName><FName type='text'>jose miguel</FName><LName type='text'>abad tirado</LName><Mobile type='text'>073943026717</Mobile><Country type='text'>Peru</Country><SA>yes</SA><SendEmails>true</SendEmails><IP>190.237.62.93</IP><CountryID>166</CountryID><Language>Spanish</Language><source>zomztest</source></additional>,Peru,1,598fa0fa-b033-964e-e204-eed2f6188f9a,<OperatingSystem>Windows NT 6.2; WOW64</OperatingSystem><UserLang>es-419</UserLang><Browser>Chrome</Browser><BrowserVersion>Chrome 35.0.1916.153</BrowserVersion><Refferer>http://www.zomztest.es/emerp/landing/masterlp/nobanslp.aspx?content=Testimonials5NoTime&mailT=630&delay=1&SA=Yes&dsp9=www.empresores.com&dsp1=&SID=236455&gclid=CKT-xcmloL8CFc9j7AodmRoAOQ</Refferer><Url>http://l.zomztest.com/lead.ashx?fname=jose+miguel&lname=abad+tirado&country=PE&email=marjos091111@hotmail.com&phone=073501475&sendmails=true&mobile=073943026717&phone_num=501475&mob_phone_num=943026717&area_code=073&mob_area_code=073&cat=masterLP&promocode=598fa0fa-b033-964e-e204-eed2f6188f9a&SID=236455&clang=ES&content=Testimonials5NoTime&mailT=630&delay=1&SA=Yes&gclid=CKT-xcmloL8CFc9j7AodmRoAOQ&dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=&dsp9=www.empresores.com&dsp10=&dsp11=google&dsp12=adsense&dsp13=/foros/26083-importar-de-poco-chile-bolivia-paraguay.html&dsp14=&dsp15=www.empresores.com</Url><IP>190.237.62.93</IP>,dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=&dsp9=www.empresores.com&dsp10=&dsp11=google&dsp12=adsense&dsp13=/foros/26083-importar-de-poco-chile-bolivia-paraguay.html&dsp14=&dsp15=www.empresores.com
7276200,B6FBEEBF-FE33-42D3-B0B8-83BF44F3C192,NULL,jose miguel abad tirado,-73501424,marjos091111@hotmail.com,236455,30/06/2014 00:01,<additional><pageName type='text'>masterLP - Testimonials5NoTime</pageName><FName type='text'>jose miguel</FName><LName type='text'>abad tirado</LName><Mobile type='text'>073943026717</Mobile><Country type='text'>Peru</Country><SA>yes</SA><SendEmails>true</SendEmails><IP>190.237.62.93</IP><CountryID>166</CountryID><Language>Spanish</Language><source>zomztest</source></additional>,Peru,1,598fa0fa-b033-964e-e204-eed2f6188f9a,<OperatingSystem>Windows NT 6.2; WOW64</OperatingSystem><UserLang>es-419</UserLang><Browser>Chrome</Browser><BrowserVersion>Chrome 35.0.1916.153</BrowserVersion><Refferer>http://www.zomztest.es/emerp/landing/masterlp/nobanslp.aspx?content=Testimonials5NoTime&mailT=630&delay=1&SA=Yes&dsp9=www.empresores.com&dsp1=&SID=236455&gclid=CKT-xcmloL8CFc9j7AodmRoAOQ</Refferer><Url>http://l.zomztest.com/lead.ashx?fname=jose+miguel&lname=abad+tirado&country=PE&email=marjos091111@hotmail.com&phone=073501475&sendmails=true&mobile=073943026717&phone_num=501475&mob_phone_num=943026717&area_code=073&mob_area_code=073&cat=masterLP&promocode=598fa0fa-b033-964e-e204-eed2f6188f9a&SID=236455&clang=ES&content=Testimonials5NoTime&mailT=630&delay=1&SA=Yes&gclid=CKT-xcmloL8CFc9j7AodmRoAOQ&dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=&dsp9=www.empresores.com&dsp10=&dsp11=google&dsp12=adsense&dsp13=/foros/26083-importar-de-poco-chile-bolivia-paraguay.html&dsp14=&dsp15=www.empresores.com</Url><IP>190.237.62.93</IP>,dsp1=&dsp2=&dsp3=&dsp4=&dsp5=&dsp6=&dsp7=&dsp8=&dsp9=www.empresores.com&dsp10=&dsp11=google&dsp12=adsense&dsp13=/foros/26083-importar-de-poco-chile-bolivia-paraguay.html&dsp14=&dsp15=www.empresores.com

我应该使用什么样的正则表达式?

1 个答案:

答案 0 :(得分:0)

您可以使用以下正则表达式:

mobile=(\d*)&phone_num=(\d*)&mob_phone_num=(\d*)

<强> Working demo

MATCH 1
1.  [1113-1123] `0786066486`
2.  [1134-1134] ``
3.  [1149-1156] `6066486`
MATCH 2
1.  [2488-2498] `0786066486`
2.  [2509-2509] ``
3.  [2524-2531] `6066486`
MATCH 3
1.  [3946-3958] `073943026717`
2.  [3969-3975] `501475`
3.  [3990-3999] `943026717`
MATCH 4
1.  [5711-5723] `073943026717`
2.  [5734-5740] `501475`
3.  [5755-5764] `943026717`