tags:

views:

61

answers:

5

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?

+1  A: 

You can parse the HTML via php to access the relevant pieces and store them in your data structure for further processing, a short introduction on PHP html parsing can be found here: http://www.onderstekop.nl/articles/114/

The MYYN
A: 

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

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

Luca Matteis
yes i can but how
moustafa
if you don't know how to google or use PHP's regex functionalty, you should probably read a bit more before doing more PHP stuff.
Luca Matteis
sure, thanks my dear
moustafa
Regex is not the best option when it comes to html :( (it might work, but if you can use other methods, please do)
AntonioCS
+1  A: 

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

AntonioCS
+1  A: 

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.

Brian Agnew
A: 

thanks for all i did it by scraping used this class simplehtmldom_1_11

moustafa
Use the DOM class. It's much much faster than simple html dom.
AntonioCS