0

I need some help with a piece of code. I'm working on the customers list of my club, I can extract email address and print them on the screen, I just can't write them into a txt. Here's the code:

<?php if ( $_POST ){ 
function extract_emails($str)
{
    $regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
    preg_match_all($regexp, $str, $m);
    return isset($m[0]) ? $m[0] : array();
} 
$xurl = $_POST['testo'];// THERE IS AN INPUT FIELD
$doc = new DOMDocument();
@$doc->loadHTMLFile($xurl);
$xpath = new DOMXpath($doc);
$wpage = $xpath->query('//body[@*]');
print_r(extract_emails($wpage->item(0)->nodeValue));
$scrivi=fopen("emails.txt","a");
fwrite($scrivi,NEED SOMETHING HERE."\n");
fclose($scrivi); 
}
?>

Everytime and anything I try the only output I found in the file is "Array".

mcr
  • 762
  • 5
  • 19
Danny
  • 1
  • You probably need to iterate the elements in the array and write each element/line or do what's suggested [here](https://stackoverflow.com/questions/2628798/print-array-to-a-file) – jDo Mar 17 '16 at 11:55

1 Answers1

0

[SOLVED] Thanks @jDo, I've solved it this way:

$mail = (extract_emails($wpage->item(0)->nodeValue));
$result = var_export($mail, true);
echo $result ;
$scrivi=fopen("emails.txt","a");
fwrite($scrivi,$result."\n");
fclose($scrivi); 
Danny
  • 1