example - ideone - capture email
$url="http://www.site.com.br/123/123/123.php?p=1&codelist=1";
$text=file_get_contents($url);
$res = preg_match_all(
"/[a-z0-9]+[_a-z0-9\.-]*[a-z0-9]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})/i",
$text,
$matches
);
//caso haja somente um email
$email = reset($matches[0])."\n";
file_put_contents('emails.txt', $email, FILE_APPEND);
// fim caso haja um email
/* caso haja mais de um email
foreach($matches[0] as $email){
file_put_contents('emails.txt', $email."\n", FILE_APPEND);
}
*/
file_get_contents - Reads all the contents of a file to a string
The function preg_match_all()
return an integer with the number of occurrences found by the regular expression.
reset()
returns the array internal pointer to the first element and returns the value of the first element of the array.
file_put_contents
writes a string to a file, if this file does not yet exist it creates the file.
FILE_APPEND
adds a value to an already created file.
The above script is for a page, but nothing prevents you from making a loop by varying the value of p
in $url
for ($x = 1; $x <= 460; $x++) {
$url="http://www.site.com.br/123/123/123.php?p=".$x."&codelist=1";
$text=file_get_contents($url);
$res = preg_match_all(
"/[a-z0-9]+[_a-z0-9\.-]*[a-z0-9]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})/i",
$text,
$matches
);
//caso haja somente um email
$email = reset($matches[0])."\n";
file_put_contents('emails.txt', $email, FILE_APPEND);
// fim caso haja um email
}
" In this system I have all my customers' data" - how are you generating the content of those pages? you can’t just go to the database?
– Sergio
Marcelo, is this data in a database or printed directly in html? Can you send an example of how these values are recorded?
– Csorgo
@Sergio, it is an old and poorly done system... it presents in html on the page itself in tables... only that it is a lot of data and I need at the moment only the emails to contact.
– Marcelo
@Csorgo, are listed like this: <tr><td bgcolor=#ECEDE8>21/11/2009<br>08:05:38</td><tr><td bgcolor=#ECEDE8><font size=1 class="slk">Status<br>Inactive<br><a href="managerial users.SP? p=1&codativacao=116034&codlist=30" style="font-family:Trebuchet MS,Tahoma,Arial,Verdana; font-size:12px; color: #ffffff; text-Decoration:None; background: #109809;"> Enable Cadastre & nbsp;</u></a></td><td bgcolor=#ECEDE8><font class="slk"></td><td bgcolor=EC#EDE8><font class="slk"> [email protected]</td>
– Marcelo
each page with an email?
– user60252
I recommend that you edit your question and provide some more information, for example: How is this data saved? This helps to better understand your problem and also to better organize the site not to get all played here in the comments.
– Francisco