简体   繁体   中英

Grab e-mail addresses from an HTML table

I have an HTML table that contains 500 e-mail addresses in this file.html . Now I want to open it with PHP and get all e-mail addresses in it and add it to an array. This means I have an HTML table and in this table 500 rows with an e-mail address in each row.

How can I get these e-mail addresses with PHP?

您可以通过php解析HTML来访问相关部分并将其存储在数据结构中以进行进一步处理,有关PHP html解析的简短介绍可以在这里找到: http : //www.onderstekop.nl/articles/114/

I agree with The MYYN's approach but I suggest you use phps DOM class to iterate through all the td's of the table and fetch the emails.

Here are some useful functions:

loadHTMLFile

and

getElementsByTagName

I would avoid regexps for all the HTML/regexp issues and use an HTML parser such as this one . It should be trivial to extract the DOM for the table and contained cells/content.

Note that a regexp for identifying emails can potentially be quite complex, depending on the variety of the emails you wish to match. SO has numerous examples.

You could use regex to match the entire HTML string with email occurrences.

http://www.regular-expressions.info/email.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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