I've wrote a relatively simple code to extract email addresses from a log file, based on a specific pattern; i'm only interested in cases when people sent emails to themselves.
This show in the log like this: <%EMAIL%> -> <%SAME-EMAIL%>
Clarification:
The <%EMAIL%> represents an email address inside "<>" characters, followed by " -> ", then followed by the same email address. This pattern may (or may not) occur multiple times in a line.
for example:
<[email protected]> -> <[email protected]> should match
<[email protected]> -> <[email protected]> should NOT match
the code i currently use:
$regx = '/(<[\S]+>)\s->\s\1/';
while ( !feof($myfile) )
{
$line = fgets($myfile);
$tmpline = $line;
if ( preg_match_all($regx, $tmpline, $tmp) )
{
$data[$caught++] = $tmp;
}
}
fclose($myfile);
My problem is, the $tmp
array doesn't store the actual addresses only the " -> " substring.
My output (print_r($data)
) looks like this:
Array
(
[0] => Array
(
[0] => ->
)
[1] => Array
(
[0] =>
)
)
...
I suspect, the problem lies in my regex pattern, but unfortunately I'm not yet capable of identifying it.
Please help.
Closing statement:
The output was correct all long, but the emails were inside <> characters, and my browser tried to parse them as HTML or XML, so they wouldn't appear when echoing them out :@
The solution was hiding in the view-source.