Examples tested against actual runtime. CI re-verifies continuously. Only documented examples are tested.
How to use
Install via yarn add locutus and import:
import { html_entity_decode } from 'locutus/php/strings/html_entity_decode'.
Or with CommonJS: const { html_entity_decode } = require('locutus/php/strings/html_entity_decode')
Use a bundler that supports tree-shaking so you only ship the functions you actually use.
Vite,
webpack,
Rollup, and
Parcel
all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
#
code
expected result
1
html_entity_decode('Kevin & van Zonneveld')
'Kevin & van Zonneveld'
2
html_entity_decode('<')
'<'
Dependencies
This function uses the following Locutus functions:
functionisObjectLike(value: PhpInput): value is PhpArrayLike<PhpInput> { returntypeof value === 'object' && value !== null }
function isPhpArrayObject<T = PhpInput>(value: PhpInput): value is PhpAssoc<T> { returnisObjectLike(value) }
function toPhpArrayObject<T = PhpInput>(value: PhpInput): PhpAssoc<T> { if (isPhpArrayObject<T>(value)) { return value }
return {} }
// php/strings/get_html_translation_table (Locutus dependency module) functionget_html_translation_table( table: string | number = 'HTML_SPECIALCHARS', quoteStyle: string | number = 'ENT_COMPAT', ): Record<string, string> { // discuss at: https://locutus.io/php/get_html_translation_table/ // original by: Philip Peterson // revised by: Kevin van Zonneveld (https://kvz.io) // bugfixed by: noname // bugfixed by: Alex // bugfixed by: Marco // bugfixed by: madipta // bugfixed by: Brett Zamir (https://brett-zamir.me) // bugfixed by: T.Wild // improved by: KELAN // improved by: Brett Zamir (https://brett-zamir.me) // input by: Frank Forte // input by: Ratheous // note 1: It has been decided that we're not going to add global // note 1: dependencies to Locutus, meaning the constants are not // note 1: real constants, but strings instead. Integers are also supported if someone // note 1: chooses to create the constants themselves. // example 1: get_html_translation_table('HTML_SPECIALCHARS') // returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
// php/_helpers/_phpTypes (Locutus helper dependency) functionisPhpArrayObject(value) { returntypeof value === 'object' && value !== null }
functiontoPhpArrayObject(value) { if (isPhpArrayObject(value)) { return value }
return {} }
// php/strings/get_html_translation_table (Locutus dependency module) functionget_html_translation_table(table = 'HTML_SPECIALCHARS', quoteStyle = 'ENT_COMPAT') { // discuss at: https://locutus.io/php/get_html_translation_table/ // original by: Philip Peterson // revised by: Kevin van Zonneveld (https://kvz.io) // bugfixed by: noname // bugfixed by: Alex // bugfixed by: Marco // bugfixed by: madipta // bugfixed by: Brett Zamir (https://brett-zamir.me) // bugfixed by: T.Wild // improved by: KELAN // improved by: Brett Zamir (https://brett-zamir.me) // input by: Frank Forte // input by: Ratheous // note 1: It has been decided that we're not going to add global // note 1: dependencies to Locutus, meaning the constants are not // note 1: real constants, but strings instead. Integers are also supported if someone // note 1: chooses to create the constants themselves. // example 1: get_html_translation_table('HTML_SPECIALCHARS') // returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
Locutus is a community effort following
The McDonald's Theory:
we ship first iterations, hoping others will improve them.
If you see something that could be better, we'd love your contribution.