获取链接组的来源并将每个链接保存到特定文件

i am trying to get a source of group of links and save the source of each link to separate file.

$urls = array(
              url1 => 'http://site1.com'
              url2 => 'http://site2.com'
              url3 => 'http://site3.com'
              );
}
$files = array(
               file1 => 'file1.html'
               file2 => 'file2.html'
               file3 => 'file3.html'
               );
foreach ($urls as $url) {
    ob_start();
    $html = file_get_contents($url);
    $doc = new DOMDocument(); // create DOMDocument
    libxml_use_internal_errors(true);
    $doc->loadHTML($html); // load HTML you can add $html

    echo $doc->saveHTML();

    $page = ob_get_contents();
    ob_end_flush();
}
foreach ($files as $file) {
    $fp = fopen("$file","w");
    fwrite($fp,$page);
    fclose($fp);
}

at this point i am stuck and it's not working

You need to read the URLs and write the files in the same loop.

foreach ($urls as $i => $url) {
    file_put_contents($files[$i], file_get_contents($url));
}

There's no need to use DOMDocument, unless you really need to parse the HTML instead of just saving the source. And there's definitely no reason to use the ob_XXX functions, just assign the results directly to variables or pass them to functions.

And as design advice, when you have related data like the URLs and filenames, don't put them in separate arrays. Put them in a single, 2-dimensional array:

$data = array(array('url' => 'http://site1.com',
                    'file' => 'file1.html'),
              array('url' => 'http://site2.com',
                    'file' => 'file2.html'),
              array('url' => 'http://site3.com',
                    'file' => 'file3.html'));

This keeps all the related items close together, and you never have to worry about the two arrays getting out of sync as you update things.

Then you can loop over this one array:

foreach ($data as $datum) {
    $html = file_get_contents($datum['url']);
    $doc = new DOMDocument();
    libxml_use_internal_errors(true);
    $doc->loadHTML($html);
    // Do stuff with $doc
    $page = $doc->saveHTML($doc);
    file_put_contents($datum['file'], $page);
}