2016-11-01 3 views
-1

나는 그의 뉴스 레터를 단어로 생성 한 다음 HTML을 MailChimp에 복사하여 발송합니다.
Word에는 이상하고 멋진 서식 아이디어가 모두 포함되어 있습니다. 대부분 서식을 유지해야하므로 서식이 사용 된 것과 일관성이 있으며 단어로 볼 수 있습니다. 모양> < V : imageData의> 태그 :PHP Preg_replace MS Word 이미지 태그 만

<td width=640 style='width:480.0pt;border-top:solid #1F497D 1.0pt;mso-border-top-themecolor: text2;border-left:none;border-bottom:solid #1F497D 1.0pt;mso-border-bottom-themecolor: text2;border-right:none;background:#1F497D;mso-background-themecolor:text2; padding:0cm 0cm 0cm 0cm;height:26.6pt'> 
<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-family:"Arial","sans-serif"; mso-ansi-language:EN-NZ;mso-fareast-language:EN-NZ;mso-no-proof:yes'><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="[email protected]@[email protected]@[email protected]@[email protected]@5xe" filled="f" stroked="f"> 
<v:stroke joinstyle="miter"/> 
<v:formulas> 
<v:f eqn="if lineDrawn pixelLineWidth 0"/> 
<v:f eqn="sum @0 1 0"/> 
<v:f eqn="sum 0 0 @1"/> 
<v:f eqn="prod @2 1 2"/> 
<v:f eqn="prod @3 21600 pixelWidth"/> 
<v:f eqn="prod @3 21600 pixelHeight"/> 
<v:f eqn="sum @0 0 1"/> 
<v:f eqn="prod @6 1 2"/> 
<v:f eqn="prod @7 21600 pixelWidth"/> 
<v:f eqn="sum @8 21600 0"/> 
<v:f eqn="prod @7 21600 pixelHeight"/> 
<v:f eqn="sum @10 21600 0"/> 
</v:formulas> 
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> 
<o:lock v:ext="edit" aspectratio="t"/> 
</v:shapetype><v:shape id="_x0000_i1033" type="#_x0000_t75" style='width:479.25pt;height:112.5pt;visibility:visible;mso-wrap-style:square'> 
<v:imagedata src="22nd%20September%20-%20Take%205...%20Your%205%20minute%20fortnightly%20roundup%20of%20alcohol%20and%20other%20drug%20news%20and%20research%202_files/image001.png" o:title=""/> 
</v:shape><![endif]--><![if !vml]><img border=0 width=639 height=150 src="22nd%20September%20-%20Take%205...%20Your%205%20minute%20fortnightly%20roundup%20of%20alcohol%20and%20other%20drug%20news%20and%20research%202_files/image025.png"v:shapes="_x0000_i1033"><![endif]></span></b><b style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-family:"Arial","sans-serif"'><o:p></o:p></span></b></p> 
</td> 

유일한 진짜 문제는 MS Word에서 SNIPPIT이, 그것은 < img> 태그 모두의 추가 여기에, 이미지를 삽입하고, < V 어떻게 좀 더 구체적으로 시도했습니다

$parsed_html = preg_replace('/<!--\[[\s\S]*?\]-->/s', '', $html); 

:

$parsed_html = preg_replace('/<!--\[if gte vml 1\]*?--><!\[if !vml\]>/s', '', $html); 
나는 MS의 모든 코드를 제거하면이 형식의 모든 사망

하지만이 작업은 정상적으로 작동하지만 너무 많이 제거됩니다. 더 나은 HTL (하하) 또는 더 나은 매치 패턴을 내보낼 방법이 있는지 알고 있습니까? 여기 http://pastebin.com/myPwnHbd

지금까지 PHP입니다 (간단한 HTML 양식에서 HTML 파일을 업로드) : http://pastebin.com/Wc7hEk7c

+1

http://stackoverflow.com/questions/11400260/remove-ms-word-html-using-php – nogad

답변

0

감사합니다, 그 스레드 점에 : 여기

전체 워드의 HTML 문서입니다 http://htmlpurifier.org/

내 최종 코드 (요약)입니다 :

<?php 

    error_reporting(0); ini_set('display_errors', FALSE); 

    require_once 'htmlpurifier-4.8.0/library/HTMLPurifier.auto.php'; 

    $html = file_get_contents($_FILES['file']['tmp_name']); 

    $config = HTMLPurifier_Config::createDefault(); 

    $config->set('Core.Encoding', 'ISO-8859-1'); 

    $config->set('AutoFormat.AutoParagraph', true); 

    $purifier = new HTMLPurifier($config); 

    $clean_html = $purifier->purify($html); 

    echo $clean_html;