2016-07-20 4 views
0

을 사용하여 간단한 html dom을 사용하여 '<'기호를 구문 분석하면 모든 기호를 구문 분석 할 수 있지만 모두 '<' 인 경우 기호가 "p<10"과 같이 나타납니다. 오류가 발생합니다. 어느 누구도 simplehtmldom을 사용하여 '<'을 파싱 할 때 도움이 될 수 있습니다.phpword

public function contentWord($section, $html_data) { 
    $html_dom = new \simple_html_dom(); 
    $html_dom->load('<html><body>' . $html_data . '</body></html>'); 
    foreach ($html_dom->find('img') as $image): 
     $pcs = explode(";", $image->src); 
     $pcsExtension = explode("/", $pcs[0]); 
     $ext = $pcsExtension[1]; 
     $file = '/public/temp/' . $this->guid() . "." . $ext; 
     $fullpath = base_path() . $file; 
     $base64string = explode(",", $pcs[1]); 
     \File::put($fullpath, base64_decode($base64string[1])); 
     $image->src = $file; 
    endforeach; 

    $html_dom_array = $html_dom->find('html', 0)->children(); 

    $initial_state = array(
     'phpword_object' => &$PHPWord, // Must be passed by reference. 
     'base_root' => "http://" . $_SERVER['HTTP_HOST'], 
     'base_path' => $_SERVER['REQUEST_URI'], 
     'current_style' => array('size' => '11', 'name' => 'arial', 'align' => 'justify'), // The PHPWord style on the top element - may be inherited by descendent elements. 
     'parents' => array(0 => 'body'), // Our parent is body. 
     'list_depth' => 0, // This is the current depth of any current list. 
     'context' => 'section', // Possible values - section, footer or header. 
     'pseudo_list' => TRUE, // NOTE: Word lists not yet supported (TRUE is the only option at present). 
     'pseudo_list_indicator_font_name' => 'Wingdings', // Bullet indicator font. 
     'pseudo_list_indicator_font_size' => '7', // Bullet indicator size. 
     'pseudo_list_indicator_character' => 'l ', // Gives a circle bullet point with wingdings. 
     'table_allowed' => TRUE, // Note, if you are adding this html into a PHPWord table you should set this to FALSE: tables cannot be nested in PHPWord. 
     'treat_div_as_paragraph' => TRUE, // If set to TRUE, each new div will trigger a new line in the Word document. 
     // Optional - no default: 
     'style_sheet' => htmltodocx_styles_example(), // This is an array (the "style sheet") - returned by htmltodocx_styles_example() here (in styles.inc) - see this function for an example of how to construct this array. 
    ); 
    htmltodocx_insert_html($section, $html_dom_array[0]->nodes, $initial_state); 
    $html_dom->clear(); 
    unset($html_dom); 
} 

'<'기호를 얻을 수있는 방법이 없습니다. 이 함수를 호출하는 동안 p <과 같은 매개 변수를 호출하십시오.

+0

PHP 소스를 업데이트하십시오. –

+0

이 오류가 발생하는 파일의 줄은 무엇입니까? – Ohgodwhy

+0

$ html_data의 매개 변수로 'p <20'을 보낼 때 – Subhod30

답변

0

simple_html_dom::load()의 소스 코드를 살펴보면 라이브러리는 < 문자를 볼 때까지 데이터를 파싱하는 것처럼 보입니다. 그런 다음이 데이터 (실제로는 DOM 노드가 아님)를 사용하여 새 simple_html_dom_node을 만들고 실패합니다.


이 라이브러리는 이미 (이 적극적으로 유지 라이브러리 인 경우에, 당신은 아마 그들은 업데이트 한하기에 문제를 제기 할 수 등),하지만 당신은 단지 그것을로드하기 전에 htmlentities()와 데이터를 인코딩 할 수 있습니다이 작업을 수행해야 간단한 HTML DOM으로.

$html_data = htmlentities($html_data); 
// '<' is now '&lt;' 

$html_dom = new \simple_html_dom(); 
$html_dom->load('<html><body>' . $html_data . '</body></html>'); 
+0

Ms 단어 파일을로드 한 후 잘못된 정규화 된 문자 오류와 같은 오류가 발생합니다. – Subhod30

+0

@ Subhod30은'$ html_data = str_replace ('<', '<', $ html_data);'(htmlentities() 대신) 작동합니까? – Sam