PHPackages                             drewm/selecta - 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. drewm/selecta

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

drewm/selecta
=============

v1.0.4(9y ago)1728MITPHPPHP &gt;=5.3

Since Jun 26Pushed 9y ago2 watchersCompare

[ Source](https://github.com/drewm/selecta)[ Packagist](https://packagist.org/packages/drewm/selecta)[ RSS](/packages/drewm-selecta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

Selecta: super-light casual templating using CSS selectors
==========================================================

[](#selecta-super-light-casual-templating-using-css-selectors)

[![Build Status](https://camo.githubusercontent.com/c2df1074e960cb5614d82d6a5174f568b49894f00845865bd1e40480a3c592d2/68747470733a2f2f7472617669732d63692e6f72672f647265776d2f73656c656374612e737667)](https://travis-ci.org/drewm/selecta)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/af7c918b6bb428d9ad1a5b6a799b5e8a4f74d0f2e370ce5df85e80e177dc072a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f647265776d2f73656c656374612f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/drewm/selecta/?branch=master)

Use a CSS selector to wrap your content with HTML tags.

```
echo Selecta::wrap('h1.welcome', 'Hello, world');
```

will output:

```
Hello, world
```

Why?
----

[](#why)

Sometimes you need to output a quick bit of HTML at a point where it's really inconvenient to use a full template. Creating strings of HTML in your code is horrible, so this something a bit more humane.

Usage
-----

[](#usage)

Currently supports IDs, classes and attribute selectors.

### Class names

[](#class-names)

```
echo Selecta::wrap('ul.list li', 'So listy');
```

will output:

```
So listy
```

### IDs

[](#ids)

```
echo Selecta::wrap('div#contact', 'Call me');
```

will output:

```
Call me
```

### Attribute and Pseudo-class selectors

[](#attribute-and-pseudo-class-selectors)

```
echo Selecta::build('input[type=radio][name=color][value=blue]:checked');
```

will output:

```

```

Currently supports `:checked` and `:disabled` pseudo-classes.

### Mix it up

[](#mix-it-up)

All these can be combined and stacked:

```
echo Selecta::build('form#contact div.field input[type=text][required]');
```

will output (indented for clarity):

```

```

Methods
-------

[](#methods)

The following methods are available:

`Selecta::wrap(selector, contents)` will wrap the contents with the tags created by the selector.

`Selecta::open(selector)` will open the tags created by the selector.

`Selecta::close(selector)` will close the tags created by the selector. Note that the order of tags is reversed - you can use the same selector string with `open()` and `close()` to get valid tag pairs.

`Selecta::build(selector, contents, open, close)` will do everything - build the tags, optionally wrap the contents, optionally open and optionally close the tags.

### Opening and closing

[](#opening-and-closing)

Don't have a template to hand but need to output some structural markup?

```
echo Selecta::open('section.sidebar div');
echo $CMS->display_all_my_weird_sidebar_junk();
echo Selecta::close('section div');
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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

Total

5

Last Release

3480d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/818b5806bb09c97b6150c8756c6abe0afd16c79097c0396a26687d88cc28638d?d=identicon)[drewm](/maintainers/drewm)

---

Top Contributors

[![drewm](https://avatars.githubusercontent.com/u/225402?v=4)](https://github.com/drewm "drewm (34 commits)")

---

Tags

selector

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewm-selecta/health.svg)

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

PHPackages © 2026

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