PHPackages                             gavinggordon/htmlentities - 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. gavinggordon/htmlentities

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

gavinggordon/htmlentities
=========================

A PHP class which allows the decoding and encoding of a wider variety of characters compared to the standard htmlentities and html\_entity\_decode functions.

4.1(10y ago)23182MITPHP

Since Apr 4Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gavinggordon/htmlentities)[ Packagist](https://packagist.org/packages/gavinggordon/htmlentities)[ Docs](http://htmlentities.gavingordon.com)[ RSS](/packages/gavinggordon-htmlentities/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (2)Versions (7)Used By (0)

HtmlEntities v4.1
=================

[](#htmlentities-v41)

[![Build Status](https://camo.githubusercontent.com/6a26873c5b016648512a595c90a3306e0573bbc5b51a6ad387843603232d5aa5/68747470733a2f2f7472617669732d63692e6f72672f676176696e67676f72646f6e2f68746d6c656e7469746965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gavinggordon/htmlentities)[![Dependency Status](https://camo.githubusercontent.com/25009f6ecb11f4749574a2729acdaa5a7984b1b66421ce49d2ee5fef9ba4493f/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537333035636265613063613335303033346265373066372f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/57305cbea0ca350034be70f7)[![Total Packagist Downloads](https://camo.githubusercontent.com/8efa08c7f263e44845a808171a105d24eb82ef32d44b0296f0597c1cb5ec7287/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676176696e67676f72646f6e2f68746d6c656e7469746965732e737667)](https://packagist.org/packages/gavinggordon/htmlentities)[![Usage License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/gavinggordon/htmlentities/blob/master/license.txt)

Description
-----------

[](#description)

The ability to encode and decode a certain set of characters called 'Html Entities' has existed since PHP4. Amongst the vast number of functions built into PHP, there are 4 nearly identical functions that are used to encode and decode html entities; despite their similarities, however, 2 of them do provide additional capabilities not available to the others.

Encoding FunctionsDecoding Functionshtmlentities¹html\_entity\_decode¹htmlspecialchars²htmlspecialchars\_decode²**¹** *htmlentities and html\_entity\_decode can only encode and decode characters within PHP's HTML translations table.*

**²** *htmlspecialchars and htmlspecialchars\_decode can only encode and decode special characters³.*

**³** *special characters are not interpreted as HTML tags and 8-bit characters are encoded as ASCII characters only.*

What Sets This Apart
--------------------

[](#what-sets-this-apart)

What sets this class apart from the rest is that this class, in addition to being able to encode and decode all of the same characters/entities that can be encoded and decoded by PHP's htmlentities() and html\_entity\_decode() functions, it can also encode and decode a very large number of characters/entities which PHP's built-in htmlentities encoding and decoding functions won't encode/decode, due to their lack of special meaning in HTML, like:

- punctuation characters;
- ASCII characters;
- Greek characters;
- Latin characters;
- Russian characters;
- Arithmetic characters;
- and tons more...

Usage
-----

[](#usage)

### Installation (via Composer)

[](#installation-via-composer)

```
    composer require gavinggordon/htmlentities

```

### Examples

[](#examples)

#### Instantiation:

[](#instantiation)

```
	include_once( __DIR__ . '/vendor/autoload.php' );

    $htmlentities = new \GGG\HtmlEntities();
```

#### Encoding:

[](#encoding)

```
    $to_encode = 'Test-,;:';
    // Set a variable containing a string of the encoded characters you wish to be encoded;

    $encoded = $htmlentities->encode( $to_encode );
    // Get the encoded result by using the encode method on the returned instance of HtmlEntities;

    echo $encoded;
    // Display the encoded result, which is of type String;
    // Test&amp;hyphen;&amp;comma;&amp;semi;&amp;colon;
```

#### Decoding:

[](#decoding)

```
   $to_decode = 'Test&amp;tilde;&amp;ast;&amp;lpar;&amp;num;';
   // Set a variable containing a string of the encoded characters you wish to be decoded;

   $decoded = $htmlentities->decode( $to_decode );
   // Get the decoded result by using the decode method on the returned instance of HtmlEntities;

   echo $decoded;
   // Display the decoded result, which is of type String;
   // Test~*(#
```

---

#### More Information

[](#more-information)

##### CodeClimate

[](#codeclimate)

Check out our [CodeClimate](https://codeclimate.com) stats by [clicking here](https://codeclimate.com/github/gavinggordon/htmlentities).

##### PHP Innovation Award

[](#php-innovation-award)

This [class](http://www.phpclasses.org/package/9698.html) has been awarded a PHP Innovation Award, provided by [PHPClasses.org](http://www.phpclasses.org). My other PHP classes are accessible online via my [GitHub profile](https://github.com/gavinggordon) or [PHPClasses.org profile](http://www.phpclasses.org/browse/author/1348645.html).

---

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

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

Recently: every ~2 days

Total

6

Last Release

3699d ago

Major Versions

1.0.0 → 2.0.12016-05-04

2.0.2 → 3.02016-05-04

3.0 → 4.02016-05-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7691513?v=4)[Gavin G Gordon](/maintainers/gavinggordon)[@gavinggordon](https://github.com/gavinggordon)

---

Top Contributors

[![gavinggordon](https://avatars.githubusercontent.com/u/7691513?v=4)](https://github.com/gavinggordon "gavinggordon (101 commits)")

---

Tags

phpformatterencodinghtmlencodedecodedecodingentitiesencoderdecoderhtmlentitiesget\_html\_translation\_tablehtml\_translation\_tabletranslation\_tablehtml\_translationv4.1

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gavinggordon-htmlentities/health.svg)

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

###  Alternatives

[dflydev/base32-crockford

Encode/decode numbers using Douglas Crockford's Base32 Encoding

14400.6k1](/packages/dflydev-base32-crockford)[delight-im/base64

Simple and convenient Base64 encoding and decoding for PHP

15167.1k6](/packages/delight-im-base64)

PHPackages © 2026

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