In PHP, how do I extract multiple e-mail addresses from a block of text and put them into an array?

前端 未结 7 2148
时光说笑
时光说笑 2020-11-30 03:19

I have a block of text from which I want to extract the valid e-mail addresses and put them into an array. So far I have...

   $string = file_get_contents(\         


        
7条回答
  •  自闭症患者
    2020-11-30 03:44

    I know this is not the question you asked but I noticed that your regex is not accepting any address like 'myemail@office21.company.com' or any address with a subdomain. You could replace it with something like :

    /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/
    

    which will reject less valid e-mail (although it is not perfect).

    I also suggest you read this article on e-mail validation, it is pretty good and informative.

提交回复
热议问题