欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php解析mht文件轉(zhuǎn)換成html的實例

 更新時間:2017年03月13日 09:12:28   投稿:jingxian  
下面小編就為大家?guī)硪黄猵hp解析mht文件轉(zhuǎn)換成html的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

php解析mht文件,使用編輯器打開可以看到base64編碼所以,mht是可以轉(zhuǎn)換成html的。

<?php

/**
 * 針對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
?>

以上這篇php解析mht文件轉(zhuǎn)換成html的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Zend?Framework框架實現(xiàn)發(fā)送郵件的方法

    Zend?Framework框架實現(xiàn)發(fā)送郵件的方法

    這篇文章主要介紹了Zend?Framework框架實現(xiàn)發(fā)送郵件的方法,實例分析了Zend?Framework使用smtp郵件類實現(xiàn)郵件發(fā)送的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-12-12
  • PHP 將逗號、空格、回車分隔的字符串轉(zhuǎn)換為數(shù)組的函數(shù)

    PHP 將逗號、空格、回車分隔的字符串轉(zhuǎn)換為數(shù)組的函數(shù)

    我們在搜索一些東西時會經(jīng)常遇到可以通過空格隔開來達到輸入多個條件的目的。今天正好項目中遇到了這個情況,就寫了一個函數(shù),將多個條件放到數(shù)組里
    2012-06-06
  • PHP HTTP 認證實例詳解

    PHP HTTP 認證實例詳解

    這篇文章主要介紹了PHP HTTP 認證實例詳解的相關(guān)資料,這里附有實現(xiàn)代碼,及對認證的知識做一個詳細的介紹說明,需要的朋友可以參考下
    2016-11-11
  • php單例模式示例分享

    php單例模式示例分享

    這篇文章主要分享了一則php單例模式的示例,設(shè)計模式這些的花點心思基本的是能夠理解的,當然要想很好的運用到項目上也是需要一定的實踐,不能只是知道了解,或者說的是很厲害很懂的,一到要實際操作就不行了,廢話就不多說了
    2015-02-02
  • Zend Framework開發(fā)入門經(jīng)典教程

    Zend Framework開發(fā)入門經(jīng)典教程

    這篇文章主要介紹了Zend Framework開發(fā)入門知識點,詳細介紹了Zend Framework開發(fā)的zend源碼下載,環(huán)境配置,基本組件使用與相關(guān)注意事項等,需要的朋友可以參考下
    2016-03-03
  • PHP生成(支持多模板)二維碼海報代碼

    PHP生成(支持多模板)二維碼海報代碼

    本篇文章給大家分享了PHP生成支持多模板二維碼海報代碼,如果大家對此有需要,可以跟著參考學習下。
    2018-04-04
  • tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法

    tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法

    這篇文章主要介紹了tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法,結(jié)合實例形式簡單分析了mongoDB數(shù)據(jù)庫及thinkPHP5連接、查詢MongoDB數(shù)據(jù)庫的基本操作技巧,需要的朋友可以參考下
    2018-01-01
  • 淺談discuz密碼加密的方式

    淺談discuz密碼加密的方式

    這篇文章主要介紹了discuz密碼加密的方式,需要的朋友可以參考下
    2014-05-05
  • php通過curl模擬登陸DZ論壇

    php通過curl模擬登陸DZ論壇

    本文章來給各位同學介紹一下關(guān)于Php CURL模擬登陸論壇并采集數(shù)據(jù)實例,如果你對利用curl模擬登錄功能有興趣可進入?yún)⒖肌?/div> 2015-05-05
  • php解壓文件代碼實現(xiàn)php在線解壓

    php解壓文件代碼實現(xiàn)php在線解壓

    這篇文章主要介紹了php解壓文件代碼,根據(jù)這個代碼可以實現(xiàn)php在線解壓功能,需要的朋友可以參考下
    2014-02-02

最新評論