下面小編就為大家帶來一篇php解析mht檔轉換成html的實例。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧
php解析mht文件,使用編輯器打開可以看到base64編碼所以,mht是可以轉換成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.php.cn/,+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檔案轉換成html的實例詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

在PHP中,可以使用session_status()或session_id()來檢查會話是否已啟動。 1)使用session_status()函數,如果返回PHP_SESSION_ACTIVE,則會話已啟動。 2)使用session_id()函數,如果返回非空字符串,則會話已啟動。這兩種方法都能有效地檢查會話狀態,選擇使用哪種方法取決於PHP版本和個人偏好。

sessionsarevitalinwebapplications,尤其是在commercePlatform之前。

在PHP中管理並發會話訪問可以通過以下方法:1.使用數據庫存儲會話數據,2.採用Redis或Memcached,3.實施會話鎖定策略。這些方法有助於確保數據一致性和提高並發性能。

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

負載均衡會影響會話管理,但可以通過會話複製、會話粘性和集中式會話存儲解決。 1.會話複製在服務器間複製會話數據。 2.會話粘性將用戶請求定向到同一服務器。 3.集中式會話存儲使用獨立服務器如Redis存儲會話數據,確保數據共享。

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

PHP會話的替代方案包括Cookies、Token-basedAuthentication、Database-basedSessions和Redis/Memcached。 1.Cookies通過在客戶端存儲數據來管理會話,簡單但安全性低。 2.Token-basedAuthentication使用令牌驗證用戶,安全性高但需額外邏輯。 3.Database-basedSessions將數據存儲在數據庫中,擴展性好但可能影響性能。 4.Redis/Memcached使用分佈式緩存提高性能和擴展性,但需額外配

Sessionhijacking是指攻擊者通過獲取用戶的sessionID來冒充用戶。防範方法包括:1)使用HTTPS加密通信;2)驗證sessionID的來源;3)使用安全的sessionID生成算法;4)定期更新sessionID。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。