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.

Related tags

Strings htmlentities
Overview

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¹ 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 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‐,;:

Decoding:

   $to_decode = 'Test˜*(#';
   // 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.


You might also like...
A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM.

A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM. s('string')-toTitleCase()-ensureRight('y') ==

"結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件。 / "Jieba" (Chinese for "to stutter") Chinese text segmentation: built to be the best PHP Chinese word segmentation module.

jieba-php "結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件,目前翻譯版本為 jieba-0.33 版本,未來再慢慢往上升級,效能也需要再改善,請有興趣的開發者一起加入開發!若想使用 Python 版本請前往 fxsjy/jieba 現在已經可以支援繁體中文!只要將字典切換為 bi

highlight.php is a server-side syntax highlighter written in PHP that currently supports 185 languages

highlight.php is a server-side syntax highlighter written in PHP that currently supports 185 languages. It's a port of highlight.js by Ivan Sagalaev that makes full use of the language and style definitions of the original JavaScript project.

Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP

Patchwork UTF-8 for PHP Patchwork UTF-8 gives PHP developpers extensive, portable and performant handling of UTF-8 and grapheme clusters. It provides

php-crossplane - Reliable and fast NGINX configuration file parser and builder
php-crossplane - Reliable and fast NGINX configuration file parser and builder

php-crossplane Reliable and fast NGINX configuration file parser and builder ℹ️ This is a PHP port of the Nginx Python crossplane package which can be

PHP library to detect and manipulate indentation of strings and files

indentation PHP library to detect and manipulate the indentation of files and strings Installation composer require --dev colinodell/indentation Usage

ColorJizz is a PHP library for manipulating and converting colors.

#Getting started: ColorJizz-PHP uses the PSR-0 standards for namespaces, so there should be no trouble using with frameworks like Symfony 2. ###Autolo

:clamp: HtmlMin: HTML Compressor and Minifier via PHP

🗜️ HtmlMin: HTML Compressor and Minifier for PHP Description HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by r

Tutorial for computer vision and machine learning in PHP 7/8 by opencv (installation + examples + documentation)
Tutorial for computer vision and machine learning in PHP 7/8 by opencv (installation + examples + documentation)

Examples detect face by cascade classifier detect face by pretrained caffe model res10_300x300_ssd by ddn module detect facemarks by LBF algorithm rec

Releases(v4.1)
  • v4.1(May 14, 2016)

    v4.1

    To learn how to use this class, check out the README.md file. Also, If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    Current Version

    • Now, even more simple to use than ever before;
    • Fixed spelling errors, which may have caused problems during the encoding/decoding process;

    Previous Versions

    • Revamped the class to allow for much easier utilization, via 2 methods:
      • encode
      • decode
    • Added several hundred more entities, bringing the number of encodable/decodable characters to over 500.
    • Fixed an issue where a character wasn't encoding/decoding;
    • Fixed an issue with composer not loading the correct package.
    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v4.0(May 9, 2016)

    v4.0

    To learn how to use this class, check out the README.md file. Also, If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    Current Version

    • Revamped the class to allow for much easier utilization, via 2 methods:
      • encode
      • decode

    Previous Versions

    • Added several hundred more entities, including ASCII characters to the list of encodable and decodable characters, bringing the total to over 500 characters.
    • Fixed an issue where a character wasn't encoding/decoding;
    • Fixed an issue with composer not loading the correct package.
    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v3.0(May 4, 2016)

    v3.0

    To learn how to use this class, check out the README.md file. Also, If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    Current Version

    • Added several hundred more entities, including ASCII characters to the list of encodable and decodable characters, bringing the total to over 500 characters.

    Previous Versions

    • Fixed an issue where a character wasn't encoding/decoding;
    • Fixed an issue with composer not loading the correct package.
    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v2.0.2(May 4, 2016)

    v2.0.2

    • Updated composer.json to reflect version change.
    • To learn how to use this class, check out the README.
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    • Fixed an issue where a character wasn't encoding/decoding;
    • Fixed an issue with composer not loading the correct package.
    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(May 4, 2016)

    v2.0.1

    • Updated composer.json to reflect version change.
    • To learn how to use this class, check out the README.
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    • Fixed an issue with composer not loading the correct package.
    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v2.0(May 4, 2016)

    v2.0

    • Fixed an issue with composer not loading the correct package.
    • To learn how to use this class, check out the README.
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    • Updated README & Fixed Error with decode function.
    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
    htmlentities-2.0.zip(9.25 KB)
  • v1.1(May 1, 2016)

    v1.1

    • This version of HtmlEntities has been overhauled internally, in comparison to the last 2 versions;
    • Although much of the inner-workings of this class have changed, it's functionality and usage process is virtually the same;
    • To learn how to use this class, check out the README.
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    • Overhauled the filesystem, and namespacing;
    • Fixed issues with file structure, namespacing, etc, which had prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Apr 8, 2016)

    v1.0.1

    • This version is just a basic production-ready package; as a result, expect there to be upcoming additions to, and modifications of, this package in the near and distant future;
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.

    Change log

    • Fixed issues with file structure, namespacing, etc, which had
      prevented unit testing to be approved via Travis.CI;
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 4, 2016)

    v1.0.0

    • This version is just a basic production-ready package; as a result, expect there to be upcoming additions to, and modifications of, this package in the near and distant future;
    • If you are experiencing an issue or issues with this package, please submit an issue report, and I will get to it as soon as I can.
    Source code(tar.gz)
    Source code(zip)
    htmlentities-1.0.0.zip(9.25 KB)
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

URLify for PHP A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project. Handles symbols from

Aband*nthecar 667 Dec 20, 2022
only 5 characters to rce

phpfuck-6characters @Y4tacker Description: only 6 characters to rce ( ) ^ 9 . ; Useage php 6character-rce.php system(\"whoami\"); (((((99999999999999

Y4tacker 12 Oct 4, 2022
A sane interface for php's built in preg_* functions

Making regex great again Php's built in preg_* functions require some odd patterns like passing variables by reference and treating false or null valu

Spatie 1.1k Jan 4, 2023
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.

?? Portable UTF-8 Description It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your

Lars Moelleken 474 Dec 22, 2022
🔡 Portable ASCII library - performance optimized (ascii) string functions for php.

?? Portable ASCII Description It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your

Lars Moelleken 380 Jan 6, 2023
A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

Max Base 4 Feb 22, 2022
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

SqlFormatter A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting

Jeremy Dorn 3.9k Jan 1, 2023
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

SqlFormatter A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting

Jeremy Dorn 3.9k Jan 3, 2023
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Motto: "Every business should have a detection script to detect mobile readers." About Mobile Detect is a lightweight PHP class for detecting mobile d

Şerban Ghiţă 10.2k Jan 4, 2023
Text - Simple 1 Class Text Manipulation Library

Text - Simple 1 Class Text Manipulation Library Do you remember PHP's string functions? If not, just wrap you text with Text! It will save a minute on

Kazuyuki Hayashi 51 Nov 16, 2021