PHPackages                             burntcaramel/glaze - 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. burntcaramel/glaze

ActiveLibrary

burntcaramel/glaze
==================

Easy to use functions for displaying HTML attributes &amp; elements, escaping text, URLs, email addresses.

1.9.3(11y ago)7912MITPHPPHP &gt;=5.3.0

Since May 12Pushed 11y ago2 watchersCompare

[ Source](https://github.com/BurntCaramel/glaze)[ Packagist](https://packagist.org/packages/burntcaramel/glaze)[ RSS](/packages/burntcaramel-glaze/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (17)Used By (2)

Glaze
=====

[](#glaze)

### *[French and Viennese pastry chefs originally invented the idea of glazing cakes as a way of preserving them—the glaze sealed off the cakes from the air and prevented them from growing stale.](http://www.epicurious.com/articlesguides/howtocook/primers/cakesfrostings)*

[](#french-and-viennese-pastry-chefs-originally-invented-the-idea-of-glazing-cakes-as-a-way-of-preserving-themthe-glaze-sealed-off-the-cakes-from-the-air-and-prevented-them-from-growing-stale)

**When displaying anything on the web it must be properly prepared for HTML.** Any text, any URL, and any HTML element’s attributes and contents must be *escaped* before they are displayed.

Normally people use functions like `htmlspecialchars()`, or they even madly paste text into their source code and manually change characters like `&` into `&amp;` and `>` into `&gt;`.

Well there’s these things called computers and you can avoid all that manual work and use much more powerful functions with baking-inspired names.

Glaze preserves the content you want to display.
------------------------------------------------

[](#glaze-preserves-the-content-you-want-to-display)

Just tell it what you want to display and let it worry about the HTML writing and escaping part. It works with nested HTML elements, attributes, text, URLs, and email addresses. My aim is to make it easier to read and write than the usual PHP ways, whilst also taking care of escaping everything by default.

Whole elements
--------------

[](#whole-elements)

Escaped elements in one line.

```
use BurntCaramel\Glaze;
use BurntCaramel\Glaze\Prepare as GlazePrepare;
use BurntCaramel\Glaze\Serve as GlazeServe;

GlazeServe::element('h1#siteTitle', 'Title');
// No need to escape the &
GlazeServe::element('h2.tagline', 'The home of examples & more');
GlazeServe::element('p.any.classes.you.need', 'Blah blah blah blah');

/* Displays: */?>

Title

The home of examples &amp; more

Blah blah blah blah

```

Or use associated array version, to specify any attributes you like:

```
GlazeServe::element(array(
	'tagName' => 'a',
	'href' => 'http://www.infinitylist.com/',
	'class' => 'externalLink'
), 'Adventure & creative videos.');

/* Displays: */?>
Adventure &amp; creative videos.
```

Self closing elements are also handled.

```
GlazeServe::element(array(
	'tagName' => 'meta',
	'name' => 'description',
	'content' => 'Site description as seen by search engines'
));

/* Displays: */?>

```

Class attributes
----------------

[](#class-attributes)

Say you want to display an HTML element’s class names where some are optional.

```
$classNames = array('post');

if (isArticle()):
	$classNames[] = 'article';

	if (isFeatureArticle()):
		$classNames[] = 'feature';
	endif;
endif;
```

You could juggle `if` statements and PHP open/close tags:

```
?>
 class="">

```

Or use Glaze, passing a string or array:

```
// The -Checking method makes sure that if `$classNames` is empty, then nothing will be displayed.
?>
>

```

Check values for attributes before displaying
---------------------------------------------

[](#check-values-for-attributes-before-displaying)

Using JSON from a web API, for example.

```
$info = array(
	'itemID' => 'fddf3tq3tt3t3',
	'published' => false,
	'genreIdentifier' => 'thriller',
	'salesCount' => 56,
	'selected' => true,
	'authorName' => 'John Smith',
	'itemDescription' => array(
		'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
		'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
		'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
	)
);

// Build a list of classes using an array, don't fuss with appending to a string
$classNamesArray = array('item', 'book');
$classNamesArray[] = !empty($info['published']) ? 'published' : 'upcoming';
$classNamesArray[] = 'genre-' .$info['genreIdentifier']; // e.g. 'genre-thriller'

$bookItemDiv = GlazePrepare::element('div');
{
	$bookItemDiv->setAttribute('id', "bookItem-{$info['itemID']}");

	// Lets you use an array of strings for class attributes.
	$bookItemDiv->addClassNames($classNamesArray);

	// Only display the attribute if variable reference $info['salesCount'] is present.
	$bookItemDiv->setAttributeChecking('data-sales-count', $info['salesCount']);
	$bookItemDiv->setAttributeChecking('data-sales-count-nope', $info['salesCount_NOPE']);

	// Only displays the attribute, with the value 'selected', if $info['selected'] is true.
	$bookItemDiv->setAttributeChecking('selected', $info['selected'], 'selected');
	$bookItemDiv->setAttributeChecking('selected-nope', $info['selected_NOPE'], 'selected');

	// Will display:
	$bookItemDiv->appendNewElement('h5.authorName',
		Glaze\check($info['authorName'])
	);
	// Will not display, as key 'authorName_NOPE' does not exist.
	$bookItemDiv->appendNewElement('h5.authorName',
		Glaze\check($info['authorName_NOPE'])
	);

	// Will display:
	$bookItemDiv->appendNewElement('p.description',
		GlazePrepare::contentSeparatedBySoftLineBreaks(
			Glaze\check($info['itemDescription'])
		)
	);
	// Will not display, as key 'itemDescription_NOPE' does not exist.
	$bookItemDiv->appendNewElement('p.description',
		GlazePrepare::contentSeparatedBySoftLineBreaks(
			Glaze\check($info['itemDescription_NOPE'])
		)
	);
}
$bookItemDiv->serve();
```

Displays:

```

John Smith

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

```

### Using already escaped information

[](#using-already-escaped-information)

```
$escapedText = 'Bangers &amp; Mash';
GlazeServe::attribute('alt', $escapedText, Glaze\TYPE_PREGLAZED);

/* Displays: */?>
 alt="Bangers &amp; Mash"
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

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

Recently: every ~7 days

Total

16

Last Release

4043d ago

Major Versions

1.9.3 → 2.0.0-beta22015-03-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1978a50b12e0f81d512c2e2c0e0488b42e60834af53bc5f49938678fa3e6bab?d=identicon)[BurntCaramel](/maintainers/BurntCaramel)

---

Top Contributors

[![royalicing](https://avatars.githubusercontent.com/u/2635733?v=4)](https://github.com/royalicing "royalicing (60 commits)")

---

Tags

htmltextEscapedisplayglazeescapingglazy

### Embed Badge

![Health badge](/badges/burntcaramel-glaze/health.svg)

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

###  Alternatives

[latte/latte

☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites. Introduces context-sensitive escaping.

1.3k15.7M680](/packages/latte-latte)[froala/wysiwyg-editor

A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers and loved by users.

5.4k306.9k3](/packages/froala-wysiwyg-editor)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48419.5M74](/packages/soundasleep-html2text)[ckeditor/ckeditor

JavaScript WYSIWYG web text editor.

5234.2M75](/packages/ckeditor-ckeditor)[tinymce/tinymce

Web based JavaScript HTML WYSIWYG editor control.

1697.5M105](/packages/tinymce-tinymce)[unisharp/laravel-ckeditor

JavaScript WYSIWYG web text editor (for laravel).

377762.3k5](/packages/unisharp-laravel-ckeditor)

PHPackages © 2026

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