PHPackages                             artem\_c/emmet - 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. artem\_c/emmet

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

artem\_c/emmet
==============

emmet implementation for php

1.0.1(1y ago)141.8k↓50%6[3 issues](https://github.com/artemBilik/emmet/issues)UnlicensePHP

Since Jan 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/artemBilik/emmet)[ Packagist](https://packagist.org/packages/artem_c/emmet)[ RSS](/packages/artem-c-emmet/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Description
===========

[](#description)

Emmet implementation for php

Installation
============

[](#installation)

Add

```
"artem_c/emmet": "~1.0"

```

to the require section of your composer.json file.

Interface
=========

[](#interface)

```

Emmet::__construct( string emmet_string );
Emmet::create(array data);
Emmet::addFunctions(array functions);

```

Global Usage
============

[](#global-usage)

Simple Usage

```
  (new Emmet('div>p>span+a>img[src=img.jpg]'))->create();

```

OR

```
  $emmet = new Emmet('tr>td{`value`}');

  foreach($data as $value){
      echo $emmet->create([ 'value' => $value ]);
  }

```

Don't use Emmet in way like

```
  foreach($data as $value){
      echo (new Emmet('tr>td{`value`}'))->create([ 'value' => $value ]);
  }

```

Because it's work like prepared Statement in PDO.
**Emmet::\_\_construct()** will prepare the html tree.
And **Emmet::create()** will use this tree.

Best practice to create a table html element is

```
echo (new Emmet(
    'table#myTable>tbody>tr.myTr*`tr_cnt`>td.title{`data[$][title]`}+td{`data[$][value]`}')
)->create(
    ['data' => [['title' => 't1', 'value' => 'v1'], ['title' => 't2', 'value' => 'v2'], ['title' => 't3', 'value' => 'v3']], 'tr_cnt' => 3]
);

```

Detail usage
============

[](#detail-usage)

\[operation\] \[ tag \[id\] \[class\] \[attributes\] \[element text node\] \[multiplication\] \] | \[ html \[multiplication\] \] | \[ text\_node \[multiplication\] \] \[operation\]

So we have Operations and Tags, Text Nodes and Html elements.

Overview
--------

[](#overview)

Emmet string consists of objects and operations. Objects represent by tag or text node or html.

```
object+object>object(object+object)

```

Tag object starts from a tag name

```
div>div>p+span

```

It can start from any charaсter except '`', '%', '{'. Tag node can has id, class, attributes, text and multiplication.

```
div#id.class[attr=value]{text}*2+span.class

```

Text node object starts from '{'. And can has multiplication

```
{text}+{another text}*3

```

Text node cann't has any child. So you cann't use '&gt;' operation to the text node object.

Html object represent by variable or function. It can has a multiplication.

```
`variable`>%function()%

```

It can has a child object.

Operations
----------

[](#operations)

( ) ^ &gt; +

Use "+" operation to add sibling to previous elements

```
'a+span'  ==== ''

```

Use "&gt;" operation to add child to previous element

```
'a>span' === ''

```

Use "^" operation to climb up on the tree

```
'p>a>img^+span' === ''

```

Use "( )" operations for groupping elements Should to know that next after ")" operation will use the first element in the brackets. Let's see.

```
'(div>p+a)+div' === '' . ''
'(div>p>a>span)>p' === '' . ' . '' . ''
'div>(div>p)^+div' === '' . ''

```

Tags
----

[](#tags)

To create a tag you can use any character.

```
`div+h1` === ''

```

You can add an id to your tag with "#"

```
'div#myDiv>span' = ''

```

You can add a class with "." Use " " to add more than one class

```
'div.class1+div.class1 class2' === ''

```

To add any other attribute use "\[ \]"

```
'option[value=12 selected]' === ''

```

To add a text inside your tag use "{ }"

```
'p{some text}' === 'some text'

```

If you need more than one elements use multiplication by "\*"

```
'p*2' === ''

```

Text Node
---------

[](#text-node)

You can create a text node without any tag. And use it like other element with "+" operation. But you cann't add a child element to text node.

```
'p+{ some text }+a' === ' some text '
'p+{ some text }*2' === ' some text  some text '

```

Variables
---------

[](#variables)

You can use a variables like a value of your id, classes, text nodes, or multiplication in your string with " ` ".

```
(new Emmet('p.`info_class`{`information`}+span'))->create([ 'information' => 'some information for user', 'info_class' => 'info'])
 === 'some information for user'

```

You have a special variable "$". which represent a number of your element. the number of element is 0. But if you use a multiplication for your element it will change.

```
echo (new Emmet('ul>li{`ul[$]`}*2'))->create(['ul' => [1,2,3]]) === '12'

```

Or if parent element has an multiplication than the child will have the same multiplication

```
echo (new Emmet(
   'table#myTable>tbody>tr.myTr*`tr_cnt`>td.title{`data[$][title]`}+td{`data[$][value]`}')
)->create(
   ['data' => $data,'tr_cnt' => count($data),]
);

```

You can use an object in your variable by '.'

```

echo (new Emmet('article{`object.title`}'))->create(['object' => new Object()]);

```

Functions
---------

[](#functions)

You can use a function in your emmet string. At first you must add a function.

```
Emmet::addFunctions(['funcName' => function() { return 'funcName';}])

```

After this you can call it inside your emmet string by using " % ".

```
echo (new Emmet('p{%funcName()%}'))->create() === 'funcName'

```

You can pass an arguments in your function

```
Emmet::addFUnctions(['funcName' => function($arg) { return ' ' . $arg . ' '; }])

```

Pass the text as argument

```
echo (new Emmet('p{%funcName(some text)%}'))->create() === ' some text '

```

Pass the variable as argument

```
echo (new Emmet('p{%funcName(`arg`)%}'))->create(['arg' => 'arg value']) === ' arg value '

```

And you can pass more than one argument

```
Emmet::addFunctions(['func' => function($a, $b, $c) { return $a.$b.$c; }]);
echo (new Emmet('p{%func(`a`, b, `c`)%}'))->create(['a' => 'aaa', 'c' => 'ccc']) === 'aaabccc'

```

Your function can be a string

```
Emmet::addFunctions(['infoHeader' => 'Information header'])
echo (new Emmet('div>header{%infoHeader()%}+section{some info}'))-create() === 'Information headersome info'

```

You can use a default functions.

```
  integer count( mixed ) // the same as 'count()' in php

```

```
  string concat (string, string, ...) // concatinate the arguments
  (new Emmet('ul>li{`cities[$]`}*%count(`cities`)%)')->create(['cities' => array('1,2,3)])

```

```
  strinf select($name, $selected, array $data, array $html_options = []) // creates Select HTML Element

```

For generating HTML code inside your function you can use the static methods of a Node class.

```
  Node::selfClosingElement($tag, array $attributes = []);
  Node::closingElement($tag, array $attributes = [], $value = '')

```

Combine value
-------------

[](#combine-value)

You can combine value of your tag or id or class etc... With strings variables and functions.

```
echo (new Emmet('p#identifier_`$`{the value of node is %getValue(`value[$]`)%, the number of node is `$`}*%count(`value`)%'))->create(['value' => [0,10,20,30,40,50]]) === 'the value of node is 0, the number of node is 0 ...the value of node is 50, the number of node is 5'

```

HTML Node
---------

[](#html-node)

HTML it is a Node of your html tree, and the value of this node is variable or function. You can add the value of the html node inside tag or another html node or sibling it.

```
Emmet::addFunctions(['htmlFunction' => function(){ return 'function html node';}])
echo (new Emmet('div>`htmlVar`+%htmlFunction()%'))->create(['htmlVar' => 'variable html node']) === 'variable html nodefunction html node'

```

Or you can add another nodes to html node. If you use a variable or your function is a string use '{{value}}' in your string. If you use a callable function use the last arg in your function

```

echo (new Emmet('div+`myP`>a+span'))->create(['myP' => '{{value}}']) === ''

Emmet::addFunction(['oneMoreP' => '{{value}}']);

echo (new Emmet('div>%oneMoreP()%>`myP`>a+a'))->create(['myP' => '{{value}}']) === ''

Emmet::addFunction(['func' => function($first, $second, $value) { return $first.' '.$second.' '.$value; }]);

echo (new Emmet('div>%func(first, `second`)%>`second`+a'))->create(['second' => 'second']) ===
'first second second'

```

Screening
---------

[](#screening)

You cat use / for screening. When you need one of the special chars inside your text you should use / before symbol.

```
[data-value=[]]  // this will generate an error
// but
[data-value=/[/]] // generate an html
data-value="[]"

```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 99.3% 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 ~2549 days

Total

2

Last Release

474d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17856b495cbc0c9927dadf787a9338ff6c80b6b523c8d53927997c363f4f4cc1?d=identicon)[artem\_c](/maintainers/artem_c)

---

Top Contributors

[![artemBilik](https://avatars.githubusercontent.com/u/10427718?v=4)](https://github.com/artemBilik "artemBilik (145 commits)")[![NeonMy](https://avatars.githubusercontent.com/u/6606819?v=4)](https://github.com/NeonMy "NeonMy (1 commits)")

---

Tags

phphtmlemmet

### Embed Badge

![Health badge](/badges/artem-c-emmet/health.svg)

```
[![Health](https://phpackages.com/badges/artem-c-emmet/health.svg)](https://phpackages.com/packages/artem-c-emmet)
```

###  Alternatives

[christianklisch/slim-minify

Minify html output in slim framework

3831.9k1](/packages/christianklisch-slim-minify)

PHPackages © 2026

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