$link="m.habrahabr.ru/post/136811/"; CreateDOC($link,"test.doc");
function CreateDOC($link,$filename) { // , $base_link=$link; $base_link=explode("/",$link); unset($base_link[count($base_link)-1]); $base_link[]=""; $base_link=implode("/",$base_link); // $get_text=file_get_contents($link); // , mht $MhtFileMaker = new MhtFileMaker(); // // , , FlexIDK preg_match_all('@<img(.*)?src="([^"]+)"@ui', $get_text, $matches); foreach ($matches[4] as $img) { $img_tmp=$img; $img_tmp_old=$img; //, ? ! if (strpos($img_tmp,"http")===FALSE) $img_tmp=$base_link.$img_tmp; // $img_array=explode("//",$img_tmp); $img_name_only=$img_array[1]; $img_name_only=explode("/",$img_name_only); unset($img_name_only[0]); $img_name_only=implode("/",$img_name_only); // ( ) $get_text=str_replace($img_tmp_old,$img_name_only,$get_text); // $MhtFileMaker->AddFile($img_tmp, $img_name_only, NULL); }; // , $MhtFileMaker->AddContents("index.html","text/html",$get_text); // $MhtFileMaker->MakeFile($filename); };
Naturally, it is possible to write on the basis of this a much more universal and direct class, but for our purposes this was enough. The main thing is that this solution works, and quickly enough. I hope it will seem useful to someone.Source: https://habr.com/ru/post/136999/
All Articles