PHP Classes

PHP HtmlEntities Encoding and Decoding: Encode and decode a longer list of HTML entities

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 257 All time: 7,839 This week: 488Up
Version License PHP version Categories
htmlentities 4.5MIT/X Consortium ...5.4.0HTML, PHP 5, Text processing
Description 

Author

This class can encode and decode a longer list of HTML entities.

It can take a given string and recognize characters that can be encoded as HTML entities. The list of supported characters is longer than the one encoded by PHP HTMLEntities.

The class can also do the opposite, i.e. decode text with encoded HTML entities similar to PHP html_entity_decode function.

Innovation Award
PHP Programming Innovation award nominee
April 2016
Number 10


Prize: 1 year subscription to the Basic Plan of an API product of choice
Since the early versions, PHP can encode text to be represented in HTML as markup entities using the HTMLEntities function. Special characters are not interpreted as HTML tags and 8 bit characters are encoded as ASCII characters only.

This class can encode and decode text with other characters not encoded by HTMLEntities, like for instance punctuation characters that does not have special meaning in HTML.

Manuel Lemos
Picture of Gavin Gordon Markowski
  Performance   Level  
Name: Gavin Gordon Markowski <contact>
Classes: 13 packages by
Country: Canada Canada
Age: 36
All time rank: 178541 in Canada Canada
Week rank: 49 Up1 in Canada Canada Up
Innovation award
Innovation award
Nominee: 5x

Documentation

HtmlEntities v4.1

Build Status Dependency Status Total Packagist Downloads Usage License

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 Functions | Decoding Functions | |--------------|--------------| | htmlentities&sup1; | html_entity_decode&sup1; | | htmlspecialchars&sup2; | htmlspecialchars_decode&sup2; |

__&sup1;__ htmlentities and html_entity_decode can only encode and decode characters within PHP's HTML translations table.

__&sup2;__ htmlspecialchars and htmlspecialchars_decode can only encode and decode special characters&sup3;.

__&sup3;__ 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 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

Installation (via Composer)

    composer require gavinggordon/htmlentities

Examples

Instantiation:

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

    $htmlentities = new \GGG\HtmlEntities();

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:

    $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

CodeClimate

Check out our CodeClimate stats by clicking here.

PHP Innovation Award

This class has been awarded a PHP Innovation Award, provided by PHPClasses.org. My other PHP classes are accessible online via my GitHub profile or PHPClasses.org profile.


  Files folder image Files (10)  
File Role Description
Files folder imagebuild (1 directory)
Plain text file .codeclimate.yml Data Auxiliary data
Plain text file .scrutinizer.yml Data Auxiliary data
Plain text file .travis.yml Data Auxiliary data
Plain text file composer.json Data Composer package file
Image file ggg_htmlentities_tests Screen Screenshot of tests
Plain text file LICENSE.txt Doc. Documentation
Plain text file license.txt Doc. Documentation
Plain text file phpunit.xml Data Auxiliary data
Plain text file README.md Doc. Information and Examples

  Files folder image Files (10)  /  build  
File Role Description
Files folder imagelogs (1 file)

  Files folder image Files (10)  /  build  /  logs  
File Role Description
  Plain text file clover.xml Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 90%
Total:257
This week:0
All time:7,839
This week:488Up