2016-07-20 1 views
0

en utilisant simplehtmldom, Son tout bien avec tous les symboles d'analyse mais quand il y a '<' signe apparaît dans le texte comme "p<10" Il donne une erreur. peut-on tous les deux m'aider sur l'analyse '<' en utilisant simplehtmldom.L'analyse du signe '<' en utilisant simple html dom avec 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); 
} 

Je ne trouve aucun moyen d'obtenir le signe '<'. lors de l'appel de cette fonction, appelez simplement avec le paramètre p < 10.

+0

Veuillez mettre à jour votre source PHP. –

+0

À quelle ligne du fichier cette erreur se produit-elle? – Ohgodwhy

+0

lorsque j'envoie 'p <20' comme paramètre pour $ html_data – Subhod30

Répondre

0

En regardant à travers le code source pour simple_html_dom::load(), il semble que la bibliothèque analyse les données jusqu'à ce qu'elles voient un caractère <. Ensuite, il essaie de créer un nouveau simple_html_dom_node en utilisant ces données (qui n'est pas réellement un nœud DOM) et échoue.


Cette bibliothèque devrait déjà faire (et, si elle était une bibliothèque gérée activement, vous pourriez soulever probablement un problème avec eux de l'avoir mis à jour), mais vous pouvez simplement encoder les données avec htmlentities() avant de le charger en DOM HTML simple.

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

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

Après cela, en chargeant le fichier Word, il donne une erreur comme une erreur de caractère qualifié illégal. – Subhod30

+0

@ Subhod30 fait '$ html_data = str_replace ('<', '<', $ html_data);' travail (au lieu de 'htmlentities()')? – Sam