python解析mht文件_php解析mht文件转换成html
php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的。
/**
* 针对Mht格式的文件进行解析
* 使用例子:
*
* function mhtmlParseBody($filename) {
if (file_exists ( $filename )) {
if (is_dir ( $filename )) return false;
$filename = strtolower ( $filename );
if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;
$o_mhtml = new mhtml ();
$o_mhtml->set_file ( $filename );
$o_mhtml->extract ();
return $o_mhtml->get_part_to_file(0);
}
return null;
}
function mhtmlParseAll($filename) {
if (file_exists ( $filename )) {
if (is_dir ( $filename )) return false;
$filename = strtolower ( $filename );
if (strpos ( $filename, '.mht', 1 ) == FALSE) return false;
$o_mhtml = new mhtml ();
$o_mhtml->set_file ( $filename );
$o_mhtml->extract ();
return $o_mhtml->get_all_part_file();
}
return null;
}
*/
class mhtparse {
var $file = '';
var $boundary = '';
var $filedata = '';
var $countparts = 1;
var $log = '';
function extract() {
$this->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) {
/*
* $str="sssss { x { xx } {xx{xx } x} x} sssss"; $range=string::getRange($str,'{','}',0); echo $range['range']; //tulem: " x { xx } {xx{xx } x} x" echo $range['behin']; //tulem: 6 echo $range['end']; //tulem: 30 (' ') -- l5pumärgist järgnev out: array('range'=>$Range,'begin'=>$Begin_firstOccurence_pos,'end'=>$End_sequel_pos) | false v1.1 2004-2006,Uku-Kaarel J5esaar,ukjoesaar@hot.ee,http://www.hot.ee/ukjoesaar,+3725110693
*/
if (empty ( $Beginmark_str ))
$Beginmark_str = '{';
$Beginmark_str_len = strlen ( $Beginmark_str );
if (empty ( $Endmark_str ))
$Endmark_str = '}';
$Endmark_str_len = strlen ( $Endmark_str );
/* $Start_pos_cache = 0; */
do {
/* !algus */
if (! is_int ( $Begin_firstOccurence_pos ))
$Start_pos_cache = $Start_pos;
/* ?algus-test */
$Start_pos_cache = @strpos ( $subject, $Beginmark_str, $Start_pos_cache );
/* this is possible start for range */
if (is_int ( $Start_pos_cache )) {
/* skip */
$Start_pos_cache = ($Start_pos_cache + $Beginmark_str_len);
/* test possible range start pos */
if (is_int ( $Begin_firstOccurence_pos )) {
if ($Start_pos_cache < $range_end_pos)
$rangeClean = 0;
elseif ($Start_pos_cache > $range_end_pos)
$rangeClean = 1;
}
/* here it is */
if (! is_int ( $Begin_firstOccurence_pos ))
$Begin_firstOccurence_pos = $Start_pos_cache;
} /* VIGA NR 0 ALGUST EI OLE */
if (! is_int ( $Start_pos_cache )) {
/* !algus */
/* VIGA NR 1 ALGUSMARKI EI LEITUD : VIIMANE VOIMALIK ALGUS */
if (is_int ( $Begin_firstOccurence_pos ) and ($Start_pos_cache < $range_end_pos))
$rangeClean = 1;
else
return 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 );
/* ok */
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;
}
/* VIGA NR 2 LOPPU EI LEITUD */
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 );
else
return false;
return array (
'range' => $Range,
'begin' => $Begin_firstOccurence_pos,
'end' => $End_sequel_pos
);
} // end getrange()
} // class
?>
python解析mht文件_php解析mht文件转换成html相关推荐
- 读取CSV文件内容,将其转换成JSON字符串输出
CsvToJsonUtil 工具类作用:读取CSV文件内容,将其转换成JSON字符串输出 转换工具类代码如下: package com.test.util;import java.io.*; impo ...
- python篮球-用Python把蔡徐坤打篮球视频转换成字符动画!
原标题:用Python把蔡徐坤打篮球视频转换成字符动画! 说到现在网络最火的梗,非"蔡徐坤打篮球"莫属.最近,蔡徐坤当仁不让地成为了娱乐圈被黑的最惨的明星. 自从2019年1月份, ...
- python咋变汉语_python实现将汉字转换成汉语拼音的库
本文实例讲述了python实现将汉字转换成汉语拼音的库.分享给大家供大家参考.具体分析如下: 下面的这个python库可以很容易的将汉字转换成拼音,其中用到了一个word.data 的字典,可点击此处 ...
- python解析mht文件_php解析mht文件转换成html的方法
本篇文章主要介绍php解析mht文件转换成html的方法,感兴趣的朋友参考下,希望对大家有所帮助. php解析mht文件,使用编辑器打开可以看到base64编码所以,mht是可以转换成html的. / ...
- python解析mht文件_php解析mht文件转换成html的实例详解
下面小编就为大家带来一篇php解析mht文件转换成html的实例.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 php解析mht文件,使用编辑器打开可以看到base64 ...
- java代码将excel文件中的内容列表转换成JS文件输出
思路分析 我们想要把excel文件中的内容转为其他形式的文件输出,肯定需要分两步走: 1.把excel文件中的内容读出来: 2.将内容写到新的文件中. 举例 一张excel表中有一个表格: 我们需要将 ...
- 怎么将文件转换成linux文件,Linux将DOS文件格式转换成UNIX文件格式的方法
dos格式文件传输到unix系统时,会在每行的结尾多一个^M,当然也 有可能看不到,但是在vi的时候,会在下面显示此文件的格式,比如 "dos.txt"[dos] 120L, 25 ...
- xsd文件转图片_图片转换成PDF格式怎么转?图片转换成PDF的软件哪个好?
图片转换成PDF格式怎么转?经验丰富的设计师在完成图片格式的设计作品后都会将图片转成PDF格式文件,这样方便保存以及参加一些设计比赛.同时我们在保存大量图片的时候也可以将图片转换成PDF文件.但是还有 ...
- json转为tfrecord格式文件怎么转_word怎么转换成pdf格式?这样转很方便
原标题:word怎么转换成pdf格式?这样转很方便 平时,大家需要创建一份新的文件时,一般都会使用word.excel或者ppt等可编辑格式文档文稿.之后,当我们要把文件发送出去的时候,也会先把其他文 ...
- php下载数组里的图片,php 读取txt文件中的内容,转换成数组,根据URL将图片下载到本地(curl爬取)...
link.txt文件内容(注意地址可以无限多) https://youimg1.c-ctrip.com/target/100m1f000001gzojc0664_D_521_391.jpg https ...
最新文章
- zabbix监控nginx,PHP-FPM,ELK报警
- 电影院票务管理系统数据库设计(2)
- 中班游戏电子计算机,幼儿园中班数学游戏:小小快递员
- JVM内存模型与垃圾回收GC
- 延长天文学家寿命的发现——纳皮尔发现对数
- linux 混杂设备 miscdevice设备介绍
- 邮政储蓄计算机笔试题,邮储总行计算机类笔试题
- Linux系统下安装es中ik分词器详解
- Python修改文件后缀名
- 从一个例子看ASCII点阵字库的应用原理
- ss1111111111111111111111111111111111111111
- CSS实现兼容浏览器的文字阴影效果
- 网页游戏外挂的设计与编写:QQ摩天大楼【三】(登陆准备-信息发送方式)
- codeforces 730 A Toda 2
- CSS3笔记(菜鸟教程)
- 芯片如何储存信息_手机上的你以为信息删了就彻底删除了?事情没那么简单
- 关于skb_make_writable()函数
- Win7系统打印机不能打印的问题
- 系统可用性量表(SUS )
- 【ART-PI】STM32H750XBH6 - 入手篇
热门文章
- 电脑右下角弹出广告解决方法
- python为在线漫画网站自制非官方API(未完待续)
- 人民大学联合今目标成立企业行为研究中心
- PL.SQL.Developer.v9.0.1.1613下载地址
- [Mysql] STR_TO_DATE函数
- 下午:准备考试——SOA解决方案架构师认证
- 第一篇:什么是IT行业
- pycharm常用快捷键总结
- 帝国军师--约森·梅尔沃德(微软技术总监)
- 海康web插件视频播放异常