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
public function f_html2docx($currVal) {
// handling tag
$el = 'i';
$tag_open = '<' . $el . '>';
$tag_close = '' . $el . '>';
$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 = '' . $el . '>';
$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 = '' . $el . '>';
$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));