/*** Created by Phpstorm.* User:kungyu* DATE:2015/12/3* time:15:30 */classMhtparse {var$file= '';var$boundary= '';var$filedata= '';var$countparts= 1;var$log= '';functionExtract () {$this -Read_filedata ();$this -File_parts ();return1;}functionSet_file ($p) {$this -File= $p;}functionGet_log () {return$this -Log;}functionFile_parts () {$lines= Explode ("\ n", substr ($this -Filedata0,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);} }functionGet_all_part_file () {return$this -Filedata;}functionGet_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] )== '--')return1;$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;}functionRead_filedata () {$handle= fopen ($this -File' R ');$this -Filedata= Fread ($handle, FileSize ($this -file));Fclose ($handle);}functionGetRange&$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;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);/ * 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) andIs_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/ * $filename = './test.mht ';if (file_exists ($filename)) {if (Is_dir ($filename)) return false;$filename = Strtolower ($filename);if (Strpos ($filename, '. mht ', 1) = = false) return false;$o _mhtml = new Mhtparse ();$o _mhtml->set_file ($filename);$o _mhtml->extract ();$res = $o _mhtml->get_part_to_file (0);Var_dump ($res);}*/
The above describes the PHP processing MHT files, including the A_star aspects of the content, I hope that the PHP tutorial interested in a friend helpful.