2016-07-20 5 views
0

mit simplehtmldom, Es ist alles in Ordnung mit allen Symbolen zu analysieren, aber wenn es '<' Zeichen im Text erscheint wie "p<10" Es gibt Fehler. kann mir helfen beide bei der Analyse '<' mit simplehtmldom.Parsing '<' Zeichen mit einfachen HTML dom mit 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); 
} 

Ich kann keinen Weg finden, '<' Zeichen zu erhalten. Rufen Sie diese Funktion auf, rufen Sie einfach mit Parameter wie p < 10.

+0

Bitte aktualisieren Sie Ihre PHP-Quelle. –

+0

An welcher Zeile der Datei tritt dieser Fehler auf? – Ohgodwhy

+0

wenn ich 'p <20' als Parameter für $ html_data – Subhod30

Antwort

0

Blick durch den Quellcode für simple_html_dom::load(), es scheint, als ob die Bibliothek Daten analysiert, bis es ein < Zeichen sieht. Dann versucht es, ein neues simple_html_dom_node zu erstellen, das diese Daten verwendet (die eigentlich kein DOM-Knoten sind) und schlägt fehl.


Diese Bibliothek sollte dies bereits tun (und, falls es sich um ein aktiv gepflegt Bibliothek waren, könnten Sie wahrscheinlich ein Problem mit ihnen zu erhöhen, um es aktualisiert haben), aber Sie können nur die Daten mit htmlentities() kodieren vor dem Einlegen in einfaches 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

senden Nach dem Laden von Ms Word-Datei gibt es Fehler wie unzulässige qualifizierte Name Zeichen Fehler. – Subhod30

+0

@ Subhod30 tut '$ html_data = str_replace ('<', '<', $ html_data);' arbeiten (statt 'htmlentities()')? – Sam