ncjoes / office-converter

PHP Wrapper for LibreOffice
MIT License
197 stars 75 forks source link

Bug in SetValue() when replace contains "&" #41

Open SeriusName opened 2 years ago

SeriusName commented 2 years ago

When usingt setValue() for replacing a variable ${variable} containing "&" the function does not respond with any error but the document will be saved corrupted and therefore you will not be able to use or open it.

Our Solution was to replace the "&" with the xml code for that character, so'&' and then it will be correctly replaced.


$variableToSearch = 'some_variable';
$variableToReplace = 'some_variable_with_&';

//Fix & error
$variableToReplace = str_replace('&','&',variableToReplace );

$templateProcessor = new TemplateProcessor($doc_source_filename);
$templateProcessor->setValue($variableToSearch,$variableToReplace);

I hope that might help!