Conn2Flow
Docs navigation

Reference / Libraries

html.php library

Editing an HTML snippet with DOMDocument: open it, change attributes, text and classes by CSS class name, and return the HTML.

Path in the Gestor bibliotecas/html.php

A DOM editing session over HTML, kept in the $_HTML['dom'] global: it opens a snippet, changes elements selected by CSS class and returns the HTML. Today only configuracao.php uses it, to hide elements (the escondido class) on configuration screens; the rest of the Gestor works with strings through modelo.php.

gestor_incluir_biblioteca('html');
html_iniciar(['valor' => $snippet]);         // or ['gestor' => true] to use $_GESTOR['pagina']
html_adicionar_classe(['consulta' => 'field', 'classe' => 'required']);
html_atributo(['opcao' => 'mudar', 'consulta' => 'field', 'atributo' => 'data-id', 'valor' => '7']);
$snippet = html_finalizar();                 // or ['gestor' => true] to write into $_GESTOR['pagina']
Function
html_iniciar(['valor' => … \| 'gestor' => true]) Loads the HTML into a DOMDocument
html_atributo(['opcao' => 'valor'\|'mudar', 'consulta', 'atributo', 'valor']) Reads the attribute of the first element with the class, or writes it on all of them
html_valor(['opcao' => 'mudar', 'consulta', 'valor']) Replaces the text (nodeValue) of every element with the class
html_adicionar_classe(['consulta', 'classe']) Adds a class
html_elemento(['opcao' => 'excluir', 'consulta']) Removes every element with the class
html_consulta(['valor' => '//xpath']) Free XPath query; returns a DOMNodeList
html_finalizar(['gestor' => true]) Serializes, strips the <html><body> the DOM adds and releases the session
html_beautify($html) Indents with the tidy extension; returns a tidy object

consulta is always a class name (not a CSS selector) and goes into the XPath unescaped.

Other side effects:

  • html_adicionar_classe() reads the class of the first element and writes it, with the new class, to every matching element: the other elements' own classes are replaced.

  • html_iniciar() uses mb_convert_encoding(…, 'HTML-ENTITIES'), deprecated in PHP 8.2 (it raises a deprecation notice).

  • DOMDocument repairs the HTML: it closes tags, moves elements and wraps loose text. The output may not match the input byte for byte.

  • html_beautify() applies stripslashes() first, which deletes backslashes from the content. It has no callers.

Functions

Generated from gestor/bibliotecas/html.php · 8 functions

8 of 8

html_iniciar

view source · line 35 ↗
html_iniciar(array|false $params = false): void

Inicializa objeto DOMDocument para manipulação HTML.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void

html_finalizar

view source · line 70 ↗
html_finalizar(array|false $params = false): string|void

Finaliza e retorna HTML do objeto DOM.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string|void
HTML processado ou void se gestor=true.

html_consulta

view source · line 113 ↗
html_consulta(array|false $params = false): DOMNodeList

Executa consulta XPath no objeto DOM.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

DOMNodeList
Resultado da consulta ou lista vazia.

html_atributo

view source · line 145 ↗
html_atributo(array|false $params = false): string|void

Manipula atributos de elementos HTML.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

string|void
Valor do atributo se opcao='valor', void se 'mudar'.

html_valor

view source · line 202 ↗
html_valor(array|false $params = false): void

Manipula valor (nodeValue) de elementos HTML.

Parameters

$paramsarray|false
Parâmetros da função.

Returns

void

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting