PHPackages                             nexocentric/silkworm - 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. nexocentric/silkworm

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

nexocentric/silkworm
====================

Silkworm is a flexible HTML generator for use in PHP projects.

v2.00(12y ago)115MITPHPPHP &gt;=5.3.0

Since Oct 4Pushed 11y ago1 watchersCompare

[ Source](https://github.com/nexocentric/silkworm)[ Packagist](https://packagist.org/packages/nexocentric/silkworm)[ Docs](http://github.com/nexocentric/silkworm)[ RSS](/packages/nexocentric-silkworm/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

(ml)Silkworm [![Build Status](https://camo.githubusercontent.com/5c166eb1b8075f94e8f0d79ba863bf2660e137fd924d772412160ed8860f85e1/68747470733a2f2f7472617669732d63692e6f72672f6e65786f63656e747269632f73696c6b776f726d2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/nexocentric/silkworm)
========================================================================================================================================================================================================================================================================================================

[](#mlsilkworm-)

[日本語はこちらです。](./README%5BJP%5D.md)
[中文说明见。](./README%5BZH%5D.md)

(ml)Silkworm, or just Silkworm, is a **m**arkup **l**anguage library for PHP to aid in the **creation** of **HTML** and **XML** documents. Silkworm acts as an abstraction layer allowing you to focus solely on PHP when you're programming eliminating the need to worry about properly formatting your HTML `\t\t\n` manually.

Silkworm generates nicely carriaged, returned and indented HTML or XML from your PHP files. The library is dynamic and can be used in a modular fashion allowing you to break up the document creation process into logical chunks throughout your program.

History
-------

[](#history)

Silkworm was built from the ground up and has been throughly tested using PhpUnit.

Changelog
---------

[](#changelog)

VersionNameChanges1.00aoinitial release1.01beigefixed code formatting1.02cyanupdated English readme1.03daidaidrafted Japanese readme1.04emeraldcompleted Japanese readme1.05fendrafted Chinese readme1.06ginfixed clipping issues, added new tests1.07huicompleted Chinese readme, removed work files2.00jadeadded some new functionality as listed below1) htmlspecialchars escaping2) ability to define extra boolean attributes3) ability to define extra self-closing tags4) ability to adjust last minute indentationfor each silkworm before outputting text5) padding to integer defined array keys forimproved and more reliable sortingchangelog on English readme file, addedadditional tests, added LICENSE fileInstallation and Configuration
------------------------------

[](#installation-and-configuration)

### Installation

[](#installation)

Silkworm has no dependencies and can be installed the following ways:

1. GitHub Copy and Include

- Copy the library from GitHub
- Move Silkworm.php to the directory of your choice
- Include Silkworm.php in the file that you'll be using it in

2. Via Composer

- Add the following to your composer requirements

```
{
  "require": {
    "nexocentric/silkworm": "dev-master"
  }
}
```

Instantiate `$html = new Silkworm();` and go.

#### Testing

[](#testing)

All tests for Silkworm have been conducted with PhpUnit. The tests are contained in the [tests folder](./tests), so feel free to run them to make sure your version is working.

### Configuration

[](#configuration)

Silkworm doesn't require any configuration before use. However, there are a number of settings that you can use as demonstrated below.

```
Silkworm::setSilkwormAlias("HyperTextGenerator"); //change the name of the class

$html = new Silkworm();
$html->setIndentation("   "); //indentation is now set to 3 spaces
$html->setSelfClosingTagStyle("xml"); // < /> vs
$html->setBooleanDisplayStyle("maximize"); //disabled="disabled" vs disabled
```

Usage
-----

[](#usage)

There are a number of ways to use Silkworm.

### Basic

[](#basic)

```
$table = array(
    array("Version", "Name", "Changes"),
    array("1.00", "ao", "initial release")
);

$html = new Silkworm();
$html->html(
    $html->head(
        $html->title("A title")
    ),
    $html->body(
        $html->p("class", "main-text", "This is Silkworm version 1.00!"),
        $html->newline(),
        $html->comment("information about silkworm"),
        $html->autoTable($table, true)
    )
);
```

### Snippet Saving

[](#snippet-saving)

You can make and save snippets as follows.

##### Setup

[](#setup)

```
$html = new Silkworm();
$html["error"] = $html->div(
    $html->p(
      "YOU MADE A BOO BOO!"
    )
);

$html["falsePositive"] = $html->div(
    $html->p(
      "Sorry, about that. My bad."
    )
);

$html["truePositive"] = $html->div(
    $html->p(
      "On second thought... that can't be... ;)"
    )
);
```

If you use the `(string)$html` as a string, all of the snippets will automatically be joined in numerical then alphabetical order.

##### Output

[](#output)

```

  YOU MADE A BOO BOO!

  Sorry, about that. My bad.

  On second thought... that can't be... ;)

```

You can also choose which snippet you would like to use.

```
(string)$html["falsePositive"];
```

If you need the snippet to include header information like ``, you can wrap the string with the following function.

```
(string)$html->stringWithDocumentHeader($html["truePositive"]);
```

### Advanced

[](#advanced)

For advanced usage please see the [examples](./examples) folder. The examples are set up and ready for display. You should be able to access the files from your browser and see how they display there. Feel free to tinker with the examples to test out the system.

Contact
-------

[](#contact)

### General

[](#general)

You can contact me via:

- Twitter: [@nexocentric](https://twitter.com/nexocentric)
- GitHub: [nexocentric](https://github.com/nexocentric)

### Bugs

[](#bugs)

If you find any bugs while using Silkworm, I'd like to know so that I can fix them as soon as possible.

Please submit the issue via GitHub and I'll contact you for more information.

### Contributing

[](#contributing)

Your contributions are greatly appreciated!

If you would like to contribute, please:

1. Fork the library on GitHub
2. Make any changes that you think will better the project
3. Make tests for the changes that you've made
4. Make a pull request
5. I'll message you about making any needed documentation changes (so that you don't make documentation changes before you know if the pull request can be accepted or not)

I'll go through the request to make sure that everything is okay and usable.\*

\[\*\] I would like to apologize in advance for not being able to accept all pull requests.

### Feedback

[](#feedback)

I would like to hear feedback, bad and good. Anything that promotes discussion is appreciated.

Acknowledgements
----------------

[](#acknowledgements)

I would like to thank all of the people who supported me through out development for all of their help and advice.

- Amy Kuwahara
- John Goodland
- Leo Lee
- Tommie Barlow
- Tom Griffin
- Wataru Kitamura

Copyright
---------

[](#copyright)

See [LICENSE](./LICENSE) file for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~23 days

Recently: every ~45 days

Total

9

Last Release

4415d ago

Major Versions

v1.07 → v2.002014-04-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/12856b611ddc1e916b2645b2bb6cd4644d4b7f7edd522efe516af1494723efbb?d=identicon)[nexocentric](/maintainers/nexocentric)

---

Top Contributors

[![nexocentric](https://avatars.githubusercontent.com/u/3537237?v=4)](https://github.com/nexocentric "nexocentric (125 commits)")

---

Tags

xmlparsergeneratorhtmlformattingFlexible

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nexocentric-silkworm/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[imangazaliev/didom

Simple and fast HTML parser

2.2k2.3M64](/packages/imangazaliev-didom)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)

PHPackages © 2026

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