Dopracowanie kodu zostawiam Tobie.
<form method="get" action="">
<textarea name="attempt1" style="background: #009F52; width: 100%;"></textarea>
<input type="submit" name="commit" />
</form>
<body style="background: darkgoldenrod;">
<?php
$sub_page = ($_GET['attempt1']) ?? '';
if($sub_page == '') {
$sub_page = array();
} else {
$sub_page = explode(',', $sub_page);
}
define('dir1', './to_files/');
$handle = opendir(dir1);
while(false !== ($entry1 = readdir($handle))) {
if(!in_array($entry1, array('.','..',false))) {
$entry2[] = $entry1;
}
}
closedir($handle);
$quantity_entry2 = count($entry2)+1;
$ch = curl_init();
foreach($sub_page as $page) {
//$page = $main_address . $page;
echo $page;
echo "<br />";
CURL_SETOPT($ch, CURLOPT_URL, trim($page));
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER, true);
//CURL_SETOPT($ch, CURLOPT_HTTPHEADER, array('Content-type: text/plain'));
$dom = curl_exec($ch);
if(!empty($dom)) { // or check status code 200, etc.
//$dom_document = new DOMDocument('1.0', 'UTF-8');
//$dom_document->loadHTML($dom);
if(!file_exists(dir1.'_'.$quantity_entry2.'.txt')) {
file_put_contents(dir1.'_'.$quantity_entry2.'.txt',strip_tags($dom));
}
$quantity_entry2++;
}
}
curl_close($ch);
?>
</body>
Pamiętaj, aby utworzyć katalog do tworzonych plików, tutaj jest to ./to_files/.