PHP Class Jyxo\Html

Author: Jaroslav HanslĂ­k
Datei anzeigen Open project: jyxo/php Class Usage Examples

Public Methods

Method Description
__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.

Private Methods

Method Description
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.

Method Details

__construct() final public method

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

fromText() public static method

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
return string

getBody() public static method

Expects valid HTML source.
public static getBody ( string $html ) : string
$html string HTML source code
return string

is() public static method

It is just an estimation.
public static is ( string $text ) : boolean
$text string Input text to be tested
return boolean

linkFromText() public static method

Converts text to a link to an url or email.
public static linkFromText ( string $text ) : string
$text string Input text
return string

removeAttributes() public static method

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
return string

removeDangerous() public static method

Removes possibly dangerous attributes that could contain XSS code from the HTML source.
public static removeDangerous ( string $html ) : string
$html string HTML source code
return string

removeInnerTags() public static method

Expects valid HTML source
public static removeInnerTags ( string $html, string $tag ) : string
$html string HTML source code
$tag string Tags to be processed
return string

removeJavascriptEvents() public static method

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
return string

removeRemoteImages() public static method

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
return string

removeTags() public static method

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
return string

repair() public static method

Required the Tidy PHP extension.
public static repair ( string $html ) : string
$html string Input HTML source
return string

toText() public static method

Converts HTML source code to plaintext.
public static toText ( string $html ) : string
$html string HTML source code
return string