php解析mht文件转换成html的实例详解

2025-10-26
网站建设限时活动促销

下面小编就为大家带来一篇php解析mht文件转换成html的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的。


read_filedata ();$this->file_parts ();return 1;}function set_file($p) {$this->file = $p;}function get_log() {return $this->log;}function file_parts() {$lines = explode ( "\n", substr ( $this->filedata, 0, 8192 ) );foreach ( $lines as $line ) {$line = trim ( $line );if (strpos ( $line, '=' ) !== FALSE) {if (strpos ( $line, 'boundary', 0 ) !== FALSE) {$range = $this->getrange ( $line, '"', '"', 0 );$this->boundary = "--" . $range ['range'];$this->filedata = str_replace ( $line, '', $this->filedata );break;}}}if ($this->boundary != '') {$this->filedata = explode ( $this->boundary, $this->filedata );unset ( $this->filedata [0] );$this->filedata = array_values ( $this->filedata );$this->countparts = count ( $this->filedata );} else {$tmp = $this->filedata;$this->filedata = array ($tmp );}}function get_all_part_file() {return $this->filedata;}function get_part_to_file($i) {$line_data_start = 0;$encoding = '';$part_lines = explode ( "\n", ltrim ( $this->filedata [$i] ) );foreach ( $part_lines as $line_id => $line ) {$line = trim ( $line );if ($line == '') {if (trim ( $part_lines [0] ) == '--')return 1;$line_data_start = $line_id;break;}if (strpos ( $line, ':' ) !== FALSE) {$pos = strpos ( $line, ':' );$k = strtolower ( trim ( substr ( $line, 0, $pos ) ) );$v = trim ( substr ( $line, $pos + 1, strlen ( $line ) ) );if ($k == 'content-transfer-encoding') {$encoding = $v;}if ($k == 'content-location') {$location = $v;}if ($k == 'content-type') {$contenttype = $v;}}}foreach ( $part_lines as $line_id => $line ) {if ($line_id <= $line_data_start)$part_lines [$line_id] = '';}$part_lines = implode ( '', $part_lines );if ($encoding == 'base64')$part_lines = base64_decode ( $part_lines );elseif ($encoding == 'quoted-printable')$part_lines = imap_qprint ( $part_lines );return $part_lines;}function read_filedata() {$handle = fopen ( $this->file, 'r' );$this->filedata = fread ( $handle, filesize ( $this->file ) );fclose ( $handle );}function getrange(&$subject, $Beginmark_str = '{', $Endmark_str = '}', $Start_pos = 0) {if (empty ( $Beginmark_str ))$Beginmark_str = '{';$Beginmark_str_len = strlen ( $Beginmark_str );if (empty ( $Endmark_str ))$Endmark_str = '}';$Endmark_str_len = strlen ( $Endmark_str );do {if (! is_int ( $Begin_firstOccurence_pos ))$Start_pos_cache = $Start_pos;$Start_pos_cache = @strpos ( $subject, $Beginmark_str, $Start_pos_cache );if (is_int ( $Start_pos_cache )) {$Start_pos_cache = ($Start_pos_cache + $Beginmark_str_len);if (is_int ( $Begin_firstOccurence_pos )) {if ($Start_pos_cache < $range_end_pos)$rangeClean = 0;elseif ($Start_pos_cache > $range_end_pos)$rangeClean = 1;}if (! is_int ( $Begin_firstOccurence_pos ))$Begin_firstOccurence_pos = $Start_pos_cache;} if (! is_int ( $Start_pos_cache )) {if (is_int ( $Begin_firstOccurence_pos ) and ($Start_pos_cache < $range_end_pos))$rangeClean = 1;elsereturn false;}if (is_int ( $Begin_firstOccurence_pos ) and ($rangeClean != 1)) {if (! is_int ( $End_pos_cache ))$End_sequel_pos = $Begin_firstOccurence_pos;$End_pos_cache = strpos ( $subject, $Endmark_str, $End_sequel_pos );if (is_int ( $End_pos_cache ) and ($rangeClean != 1)) {$range_current_lenght = ($End_pos_cache - $Begin_firstOccurence_pos);$End_sequel_pos = ($End_pos_cache + $Endmark_str_len);$range_end_pos = $End_pos_cache;}if (! is_int ( $End_pos_cache ))if ($End_pos_cache == false)return false;}} while ( $rangeClean < 1 );if (is_int ( $Begin_firstOccurence_pos ) and is_int ( $range_current_lenght ))$Range = substr ( $subject, $Begin_firstOccurence_pos, $range_current_lenght );elsereturn false;return array ('range' => $Range,'begin' => $Begin_firstOccurence_pos,'end' => $End_sequel_pos );} // end getrange()} // class?>

标签: mht文件转换pdf

本文地址:https://www.lifejia.cn/news/209818.html

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:cloudinto#qq.com(把#换成@)