PHP Класс Jyxo\Html

Автор: Jaroslav Hanslík
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( ) Constructor preventing from creating instances of a static class.
fromText ( string $text, boolean $convertLinks = true ) : string Converts text to HTML source code.
getBody ( string $html ) : string Returns contents from the given HTML source.
is ( string $text ) : boolean Tests if the given text contains at least one HTML tag.
linkFromText ( string $text ) : string Converts text to a link to an url or email.
removeAttributes ( string $html, array $attributes = [] ) : string Removes given attributes from the HTML source.
removeDangerous ( string $html ) : string Removes possibly dangerous attributes that could contain XSS code from the HTML source.
removeInnerTags ( string $html, string $tag ) : string Removes tags of the same type nested into each other from the HTML source.
removeJavascriptEvents ( string $html ) : string Removes all javascript events from the HTML source.
removeRemoteImages ( string $html ) : string Removes foreign images from the HTML source.
removeTags ( string $html, array $tags = [] ) : string Removes given tags from the HTML source.
repair ( string $html ) : string Fixes an invalid HTML source, unifies quotes and removes unnecessary whitespace.
toText ( string $html ) : string Converts HTML source code to plaintext.

Приватные методы

Метод Описание
blockquoteToText ( string $text ) : string Converts citations into plaintext.
linkToText ( string $text ) : string Converts HTML links into plaintext.
listToText ( string $text ) : string Converts HTML lists to plaintext.

Описание методов

__construct() закрытый публичный Метод

Constructor preventing from creating instances of a static class.
final public __construct ( )

fromText() публичный статический Метод

Converts text to HTML source code.
public static fromText ( string $text, boolean $convertLinks = true ) : string
$text string Input text
$convertLinks boolean Convert urls and emails to links
Результат string

getBody() публичный статический Метод

Expects valid HTML source.
public static getBody ( string $html ) : string
$html string HTML source code
Результат string

is() публичный статический Метод

It is just an estimation.
public static is ( string $text ) : boolean
$text string Input text to be tested
Результат boolean

linkFromText() публичный статический Метод

Converts text to a link to an url or email.
public static linkFromText ( string $text ) : string
$text string Input text
Результат string

removeAttributes() публичный статический Метод

If no attributes are given, the default set will be used. Expects valid HTML source.
public static removeAttributes ( string $html, array $attributes = [] ) : string
$html string HTML source code
$attributes array Attributes to be removed
Результат string

removeDangerous() публичный статический Метод

Removes possibly dangerous attributes that could contain XSS code from the HTML source.
public static removeDangerous ( string $html ) : string
$html string HTML source code
Результат string

removeInnerTags() публичный статический Метод

Expects valid HTML source
public static removeInnerTags ( string $html, string $tag ) : string
$html string HTML source code
$tag string Tags to be processed
Результат string

removeJavascriptEvents() публичный статический Метод

If it is necessary to remove only certain events, the removeAttributes() method can be used. Expects valid HTML source.
public static removeJavascriptEvents ( string $html ) : string
$html string HTML source code
Результат string

removeRemoteImages() публичный статический Метод

Keeps tags (only set the value about:blank into its src attribute), because removing the tag entirely could affect the page layout. Expects valid HTML source.
public static removeRemoteImages ( string $html ) : string
$html string HTML source code
Результат string

removeTags() публичный статический Метод

If no tags are given, the default set is used. Expects valid HTML code.
public static removeTags ( string $html, array $tags = [] ) : string
$html string HTML source code
$tags array Tags to be removed
Результат string

repair() публичный статический Метод

Required the Tidy PHP extension.
public static repair ( string $html ) : string
$html string Input HTML source
Результат string

toText() публичный статический Метод

Converts HTML source code to plaintext.
public static toText ( string $html ) : string
$html string HTML source code
Результат string