PHP
17
Вклад в тег
$html = '';
foreach($links as $link) {
//decode url to cyrillic
$linkDecoded = urldecode($link);
//if url contains unneeded words, delete them
if ( (strpos($linkDecoded, 'Категори') === false) && (strpos($linkDecoded, 'Википедия') === false) &&
(strpos($linkDecoded, 'index.php') === false) && (strpos($linkDecoded, 'Файл') === false) &&
(strpos($linkDecoded, '#') === false) ) {
//if $linkDecoded[0] === '/' -> add 'https://ru.wikipedia.org'
if ($linkDecoded[0] === '/') {
$linkDecoded = 'https://wikipedia.ru.org' . $linkDecoded . '<br>';
// 5 === len(wiki/); https://stackoverflow.com/questions/11290279/get-everything-after-word
$title = substr($linkDecoded, strpos($linkDecoded, 'wiki/') +5);
echo $linkDecoded;
//не было тут его, если что - убрать
$html .= file_get_contents($url);
}
}
}
//DOMpdf -> pdf
$options = new Options();
$options->set('defaultFont', 'DejaVu Sans');
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
//(Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
//title is basename === https://wikipedia.ru.org/wiki/ -> Протокол_передачи_данных
$dompdf->stream($title);