Files
anpdf/app/functions/xhtmltransform.php
Andrey Kuvshinov d91466c5d9 add readbook
2020-05-24 17:10:45 +03:00

60 lines
1021 B
PHP

<?php
function pagehtml($html, $page, $limit){
if ($page == 1){
$start = $limit;
$rstart = 0;
}
else {
$prevpage = $page - 1;
$start = $prevpage * $limit;
$r_start = endparagraf($html, $start);
}
$endpos = $page * $limit;
$r_end = endparagraf($html, $endpos);
$len = $r_end - $r_start;
return substr($html, $r_start, $len);
}
function endparagraf($html, $pos){
$end = strpos($html, '</p>', $pos);
if ($end)
return $end;
else
return false;
}
//удаляем xtml
function convert2html($xfile){
if (!file_exists($xfile)){
echo 'file not found';
return '';
}
$xhtml = file_get_contents($xfile);
$result = str_replace('</body>', '', $xhtml);
$result = str_replace('</html>', '', $xhtml);
//$start_style =(strpos('<style>', $result))
if ($pos = strpos('<body', $result)){
$result = substr($result, $pos-1);
}
return $result;
}