Hello,
You need to use phpdocx 7.5 and WordFragments. For example:
$docx = new CreateDocx();
$mergeField1 = new WordFragment($docx);
$mergeField1->addMergeField('MyMergeField1', null, array('underline' => 'dash'));
$mergeField2 = new WordFragment($docx);
$mergeParameters = array(
'textBefore' => 'A mergefield example: ',
'textAfter' => ' and some text afterwards.'
);
$mergeField2->addMergeField('MyMergeField2', $mergeParameters, array('color' => 'B70000'));
$text = array();
$text[] = $mergeField1;
$text[] = array(
'text' => ' ',
);
$text[] = $mergeField2;
$docx->addText($text);
$docx->createDocx('document');
Regards.