nguyenhiep/docxfindandreplace

Find and replace variables in a DOCX template.

Maintainers

Package info

github.com/nguyenhiepvan/docxfindandreplace

pkg:composer/nguyenhiep/docxfindandreplace

Statistics

Installs: 105

Dependents: 0

Suggesters: 0

Stars: 0

2.0.0 2020-12-21 04:37 UTC

This package is auto-updated.

Last update: 2026-02-23 20:20:24 UTC


README

This is a simple find and replace utility for DOCX files. Simple way to take a DOCX template, map some variables, and save a new copy.

Installation

Via Composer

$ composer require nguyenhiep/docxfindandreplace

Usage

In your DOCX template you will need to wrap any variables you would like to replace with curly braces (e.g. firstname). You can use regex expressions as key

\Nguyenhiep\DocxFindAndReplace\Docx::create(__DIR__ . "/template.docx")->replace(
    [
        "firstname"                                         => "nguyen",
        "lastname"                                          => "hiep",
        "/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}/" => "nguyenhiepvan.bka@gmail.com"
    ]
)->save(__DIR__ . '/newfile.docx');