Library
Class

Library\Helper\Html

class Html

HTML language helper

As for all helpers, all methods are statics.

For convenience, the best practice is to use:

use Library\Helper\Html as HtmlHelper;

Methods

static bool hasId(string $reference)

Verify if a reference is already defined in the DOM IDs register

static string getId(string $reference = null, string|bool $base_id = null)

Get a DOM unique ID

static string getNewId(string $reference = null, string|bool $base_id = null)

Create and get a new DOM unique ID

static  setHtmlTagClosure(string $closure)

Set the HTML tags closure (/> by default)

static string writeHtmlTag(string $tag_name, string $content = '', array $attrs = array(), bool $intag_close = false)

Build an HTML string for a specific tag with attributes

static string parseAttributes(array $attrs = array())

Build an attributes HTML string from an array like variable => value pairs

static string javascriptProtect(string $str = '', bool $protect_quotes = false)

Build an HTML string to use in javascripts attributes or functions

Details

at line 55
static public bool hasId(string $reference)

Verify if a reference is already defined in the DOM IDs register

Parameters

string $reference The reference to search

Return Value

bool True if the reference exists in the register, false otherwise

at line 67
static public string getId(string $reference = null, string|bool $base_id = null)

Get a DOM unique ID

Parameters

string $reference A reference used to store the ID (and retrieve it - by default, a uniqid)
string|bool $base_id A string that will be used to construct the ID, if set to true, the reference will be used as $base_id)

Return Value

string The unique ID created or the existing one for the reference if so

at line 85
static public string getNewId(string $reference = null, string|bool $base_id = null)

Create and get a new DOM unique ID

Parameters

string $reference A reference used to store the ID (and retrieve it - by default, a uniqid)
string|bool $base_id A string that will be used to construct the ID, if set to true, the reference will be used as $base_id)

Return Value

string The unique ID created

at line 119
static public setHtmlTagClosure(string $closure)

Set the HTML tags closure (/> by default)

Parameters

string $closure The tag closure string

at line 133
static public string writeHtmlTag(string $tag_name, string $content = '', array $attrs = array(), bool $intag_close = false)

Build an HTML string for a specific tag with attributes

Parameters

string $tag_name The tag name
string $content The tag content
array $attrs An attributes array
bool $intag_close Can this kind of tag be directly closed (default is false)

Return Value

string The HTML string for the tag

at line 150
static public string parseAttributes(array $attrs = array())

Build an attributes HTML string from an array like variable => value pairs

Parameters

array $attrs The attributes array

Return Value

string The attributes string ready for HTML insertion

at line 166
static public string javascriptProtect(string $str = '', bool $protect_quotes = false)

Build an HTML string to use in javascripts attributes or functions

Parameters

string $str The HTML string to protect
bool $protect_quotes Protect all quotes (simple and double) with a slash

Return Value

string The HTML string ready for javascript insertion