Skip to content

Special Characters, cause xml problems #671

Closed
@rhousham

Description

@rhousham

Hi when using the template processor and the setName function e.g
Saving as a doc file.

        $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template);
        $templateProcessor->setValue('SOMETEXT',$text);
       $templateProcessor->saveAs($file);

You need to htmlspecialchars the $text because otherwise if it contains a & or presumably other special chars this will break the file and you cannot open it. (unless you want to go through the faff of turning into a zip file, finding the & in the document.xml and changing it to & a m p; ! )

So hence

       $text = htmlspecialchars($text);

above it is required

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions