OpenTbs convert html tags to MS Word tags

后端 未结 3 2099
忘了有多久
忘了有多久 2021-01-07 13:55

I am using OpenTbs, http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html.

I have a template.docx and am able to replace fields with content but if th

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 14:10

    public function f_html2docx($currVal) {
    
        // handling  tag
    
        $el = 'i';
        $tag_open  = '<' . $el . '>';
        $tag_close = '';
        $nb = substr_count($currVal, $tag_open);
    
        if ( ($nb > 0) && ($nb == substr_count($currVal, $tag_open)) ) {
            $currVal= str_replace($tag_open,  '', $currVal);
            $currVal= str_replace($tag_close, '', $currVal);
        }
    
        // handling  tag
    
        $el = 'b';
        $tag_open  = '<' . $el . '>';
        $tag_close = '';
        $nb = substr_count($currVal, $tag_open);
    
        if ( ($nb > 0) && ($nb == substr_count($currVal, $tag_open)) ) {
            $currVal= str_replace($tag_open,  '', $currVal);
            $currVal= str_replace($tag_close, '', $currVal);
        }
    
        // handling  tag
    
        $el = 'u';
        $tag_open  = '<' . $el . '>';
        $tag_close = '';
        $nb = substr_count($currVal, $tag_open);
    
        if ( ($nb > 0) && ($nb == substr_count($currVal, $tag_open)) ) {
            $currVal= str_replace($tag_open,  '', $currVal);
            $currVal= str_replace($tag_close, '', $currVal);
        }
    
        // handling 
    tag $el = 'br'; $currVal= str_replace('
    ', '', $currVal); return $currVal; } public function f_handleUnsupportedTags($fieldValue){ $fieldValue = strip_tags($fieldValue, '
    '); $fieldValue = str_replace(' ',' ',$fieldValue); $fieldValue = str_replace('
    ','
    ',$fieldValue); return $fieldValue; }

    Now call this function as:

    $fieldVal = $this->f_html2docx($this->f_handleUnsupportedTags($fieldVal));
    

提交回复
热议问题