PHPackages                             buttress/phpx - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. buttress/phpx

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

buttress/phpx
=============

PHP DOM but intuitive

v0.2(2y ago)24261MITPHPPHP &gt;8

Since Mar 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/buttress/phpx)[ Packagist](https://packagist.org/packages/buttress/phpx)[ RSS](/packages/buttress-phpx/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

 ``

 An intuitive DOMDocument wrapper that makes it easy to write safe valid HTML in plain PHP.

---

```
$x = new Buttress\Phpx\Phpx();

$github = 'https://github.com/buttress/phpx';

echo $x->render(
    $x->main(class: 'content', c: [
        $x->h1(id: 'title', c: 'Hello World!'),
        $x->p(c: [
            'Brought to you by ',
            $x->a(href: $github, c: 'PHPX')
        ]),
    ])
);
```

becomes

```

    Hello World!

        Brought to you by PHPX

```

Installation
------------

[](#installation)

To install PHPX, use composer:

```
composer require phpx/phpx
```

Usage
-----

[](#usage)

```
/** Basic Usage */

// foo
$x->render($x->span(c: 'Foo'));

// foo
$x->render($x->a(href: '#', c: 'Foo'));

// Helloworld
$x->render($x->div(c: [
    $x->span(c: 'Hello'),
    $x->strong(c: 'world'),
]));

// Context specific XSS protection
$xss = '\'""';

// '"&lt;&gt;"
$x->render($x->span(title: $xss, c: $xss));
```

### Advanced Usage

[](#advanced-usage)

```
/**
 * $x->if : Conditional
 */

// Renders either: There are 100 items
// or No items found

$total = 100;
$result = $x->render(
    ...$x->if(
        $total > 0,
        // if
        fn() => $x->div(c: ['There are ', $x->strong(c: (string) $total), ' items']),
        // else
        fn() => $x->div(c: 'No items found.')
    )
);

/**
 * $x->foreach : Loop over a set of items
 */

$features = ['safe', 'valid', 'simple'];
// safevalidsimple
$result = $x->render(
    ...$x->foreach($features, fn(string $feature) => $x->li(c: ucfirst($feature)))
);

/**
 * $x->with : Capture a variable
 */

// Only run `getProduct()` when `$test` is true
$result = $x->render(
    $x->div(c: [
        ...$x->if($test, fn() => $x->with(getProduct(), fn(Product $product) => [
            $x->h3(c: $product->title),
            $x->p(c: $product->description)
        ]))
    ])
);

/**
 * Mix HTML and PHPX
 */
?>

    The best product around

```

Related Projects
----------------

[](#related-projects)

- [PHPX Compile](https://github.com/buttress/phpx-compile) An experimental compiler for PHPX. Significantly reduces function calls.
- [PHPX Templates](https://github.com/buttress/phpx-templates) An experimental template engine built around PHPX and PHPX Compile.

Contributing
------------

[](#contributing)

Contributions to PHPX are always welcome! Feel free to fork the repository and submit a pull request.

License
-------

[](#license)

PHPX is released under the MIT License.

Githooks
--------

[](#githooks)

To add our githooks and run tests before commit:

```
git config --local core.hooksPath .githooks
```

Support
-------

[](#support)

If you encounter any problems or have any questions, please open an issue on GitHub.

Thanks for checking out PHPX ❤️

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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 ~3 days

Total

2

Last Release

797d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/842d2fe13512e82f0f9b6f0d79dba8eba1595a3cefd31dd51723960436133307?d=identicon)[KorvinSzanto](/maintainers/KorvinSzanto)

---

Top Contributors

[![KorvinSzanto](https://avatars.githubusercontent.com/u/1007419?v=4)](https://github.com/KorvinSzanto "KorvinSzanto (21 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/buttress-phpx/health.svg)

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

PHPackages © 2026

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