PHPackages                             philgale92/docx - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. philgale92/docx

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

philgale92/docx
===============

PHP Based Docx Parser

3.9(5y ago)381.1k18MITPHPPHP &gt;=5.4.0

Since Feb 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/PhilGale92/docx)[ Packagist](https://packagist.org/packages/philgale92/docx)[ RSS](/packages/philgale92-docx/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)DependenciesVersions (16)Used By (0)

Docx Parser
===========

[](#docx-parser)

**A PHP Based Docx Parser**

### Installation

[](#installation)

Composer (cli): `composer require philgale92/docx:3.*`

Composer (file): Add the following to your `composer.json` file:

```
    "require": {
        "philgale92/docx": "3.*"
    }

```

Manual: Files within `src` follow the PSR-0 format.

### Supports

[](#supports)

- Paragraphs (basic text)
- Text attributes (bold, underline, italic, tabbed, sub &amp; sup script)
- Images
- Lists
- Hyperlinks
- Tables (colspans, vertical merged cells etc)
- Composer support
- Word Styles
- Custom attribute loading (see usage)
- Textboxes

### USAGE

[](#usage)

```

/*
* Create the parse object which converts the file into internalised objects
*/
$parser = new \PhilGale92Docx\Docx($absolutePathToDocxFile );

/*
 * Attach style info (if any)
 */
 $parser->addStyle(
     (new \PhilGale92Docx\Style())
     ->setStyleId('standardPara')
     ->setHtmlClass('custom')
     ->setHtmlTag('p') // 'p' is default behaviour
 );

 /*
  * Here is an example of a MetaData attribute style
  * (Lets pull out the titleStyle directly)
  */
$parser->addStyle(
    (new \PhilGale92Docx\Style())
    ->setStyleId('0TitleName')

    // By setting this as metaData, we can pull in
    // any content where this style is used in a seperate call.
    // It also removes the content from the standard render

    ->setIsMetaData(true)
    // By default the metaData is parsed as HTML
    // But if you need to get the literal plain text then we can do that too
    ->setMetaDataRenderMode(\PhilGale92Docx\Docx::RENDER_MODE_PLAIN)
);

/*
 * Here is an example of a heading style
 */
$parser->addStyle(
    (new \PhilGale92Docx\Style())
    ->setStyleId('1HeadingStyle')
    ->setHtmlTag('h2')
    ->setHtmlClass('custom')
);

/*
* Here is an example where we want to wrap all adjacent styles
* of this name with a div
*/
$parser->addStyle(
    (new \PhilGale92Docx\Style())
    ->setStyleId('3Boxgreytint')
    ->setBoxSimilarSiblings(true) // enable boxing behaviour
    ->setBoxClassName('box-style-tint-grey') // class of wrapping div
);

/*
 * You can also create word styles that make text lists
 * this is in addition to the standard list detection
*/
$parser->addStyle(
    (new \PhilGale92Docx\Style())
    ->setStyleId('4Numberedlist')
    ->setListHtmlTag('ol') // Takes 'ul' or 'ol'. 'ul' is default behaviour
    ->setListLevel(1) // the indentation level, must be > 0
);

/*
 * Now parse the xml into internal objects
*/
$parser->parse(); // Optional, ran automatically by ->render() if not ran yet

/*
* Now render the parser into html string
*/
echo $parser
    ->render(\PhilGale92Docx\Docx::RENDER_MODE_HTML)
;
/*
 * We can grab any metaData content after ->parse() is performed
 * ->getMetaData() runs ->parse() if not ran yet
*/
var_dump(
    $parser->getMetaData() // also takes $styleId of metaData as an argument
);

/*
 * Are there any styles we forgot to declare?
 */
var_dump($parser->getDetectedStyles());
```

### Recommended CSS

[](#recommended-css)

Here is some basic css styling you can apply as a starting point.

```
table {
    border-collapse:collapse;
}
th {
    text-align: left;
    text-transform: none;
}
td, th {
    vertical-align:top;
    background-clip:padding-box;
    border:1px solid #000000;
    color: #414042;
    height: 34px;
    padding-left: 6px;
    position: relative;
}
td.has_subcell  {
    padding-left:0;
}
table table {
    width:100%;
}
td td {
    height:72px;
    border:none;
    border-bottom:1px solid black;
    min-width:110px;
}
td table tr:last-of-type td {
    border-bottom:0;
}
span.indent {
    padding-left:36px;
}
```

====

### Requirements:

[](#requirements)

- PHP &gt;= 5.4

====

### Whats new (v1-&gt;v2)

[](#whats-new-v1-v2)

- Plugged into composer (psr-0)
- Refactored the architecture to be easier to maintain, and be properly OOP.
- Proper priv/prot/public usage.
- Removed all dynamically set properties in all objects
- All domElements are now treated equally, so the order is preserved in all cases.
- RenderMode is properly propagated throughout, so rendering to other formats is now better supported.
- Adding customised tag rendering easier to handle
- No more archaic arrays at the pre-process stage, so its easier to see how it works.
- Tidied up PHPDocs throughout

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 96% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~136 days

Total

12

Last Release

2126d ago

Major Versions

2.1 → 3.02019-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/3797505f8cb46649da5701d507216cb7f4e8a9a4b9e2559aaa540c49e517d3e4?d=identicon)[PhilGale92](/maintainers/PhilGale92)

---

Top Contributors

[![PhilGale92](https://avatars.githubusercontent.com/u/2852603?v=4)](https://github.com/PhilGale92 "PhilGale92 (24 commits)")[![pedxyuyuko](https://avatars.githubusercontent.com/u/39913604?v=4)](https://github.com/pedxyuyuko "pedxyuyuko (1 commits)")

### Embed Badge

![Health badge](/badges/philgale92-docx/health.svg)

```
[![Health](https://phpackages.com/badges/philgale92-docx/health.svg)](https://phpackages.com/packages/philgale92-docx)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

140439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
