add transform xhtml
This commit is contained in:
57
app/functions/xhtmltransform.php
Normal file
57
app/functions/xhtmltransform.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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)){
|
||||
return '';
|
||||
}
|
||||
|
||||
$xhtml = file_get_contents($xfile);
|
||||
|
||||
$result = str_replace('</body>', '', $xhtml);
|
||||
$result = str_replace('</html>', '', $xhtml);
|
||||
|
||||
if ($pos = strpos('<body', $result)){
|
||||
$result = substr($result, $pos+1);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user