This draft of the documentation remains immature. While we have made attempt to be thorough and accurate, you may encounter errors. If you discover any deficiencies, please let us know at info@kingdesk.com
This page is a subset of the documentation of the functionality provided by the PHP Parser project.parseHTML Get Methods
- get_all()
- get_locked()
- get_unlocked()
- get_comments()
- get_locked_comments()
- get_unlocked_comments()
- get_dtd()
- get_locked_dtd()
- get_unlocked_dtd()
- get_cdata()
- get_locked_cdata()
- get_unlocked_cdata()
- get_xml()
- get_locked_xml()
- get_unlocked_xml()
- get_tags()
- get_locked_tags()
- get_unlocked_tags()
- get_text()
- get_locked_text()
- get_unlocked_text()
- get_tags_by_name()
- get_tag_by_id()
- get_tags_by_class()
- get_tags_by_attribute()
- get_children()
get_all()
Description
array get_all ( )
A method of class parseHTML. Returns an array of all tokens, regardless of type or locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all tokens, regardless of type or locked/unlocked status.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all non-text tokens
// $unlocked contains all text tokens
?>
get_locked()
Description
array get_locked ( )
A method of class parseHTML. Returns an array of all locked tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked tokens, regardless of type.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all non-text tokens
// $unlocked contains all text tokens
?>
get_unlocked()
Description
array get_unlocked ( )
A method of class parseHTML. Returns an array of all unlocked tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked tokens, regardless of type.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_all();
$locked = $parsedHTML->get_locked();
$unlocked = $parsedHTML->get_unlocked();
// at this point:
// $tokens contains all tokens
// $locked contains all non-text tokens
// $unlocked contains all text tokens
?>
get_comments()
Description
array get_comments ( )
A method of class parseHTML. Returns an array of all HTML Comment tokens, regardless of locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all HTML Comment tokens, regardless of locked/unlocked status.
Examples
<?php
$html = "<p>some text</p><!-- a comment -->";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked contains all HTML Comment tokens
// $unlocked is empty
$parsedHTML->unlock_comments();
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked is empty
// $unlocked contains all HTML Comment tokens
?>
get_locked_comments()
Description
array get_locked_comments ( )
A method of class parseHTML. Returns an array of all locked HTML Comment tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked HTML Comment tokens.
Examples
<?php
$html = "<p>some text</p><!-- a comment -->";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked contains all HTML Comment tokens
// $unlocked is empty
$parsedHTML->unlock_comments();
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked is empty
// $unlocked contains all HTML Comment tokens
?>
get_unlocked_comments()
Description
array get_unlocked_comments ( )
A method of class parseHTML. Returns an array of all unlocked HTML Comment tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked HTML Comment tokens.
Examples
<?php
$html = "<p>some text</p><!-- a comment -->";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked contains all HTML Comment tokens
// $unlocked is empty
$parsedHTML->unlock_comments();
$tokens = $parsedHTML->get_comments();
$locked = $parsedHTML->get_locked_comments();
$unlocked = $parsedHTML->get_unlocked_comments();
// at this point:
// $tokens contains all HTML Comment tokens
// $locked is empty
// $unlocked contains all HTML Comment tokens
?>
get_dtd()
Description
array get_dtd ( )
A method of class parseHTML. Returns an array of all Document Type Definitions tokens, regardless of locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all Document Type Definitions tokens, regardless of locked/unlocked status.
Examples
<?php
$html = "<!DOCTYPE html ><html>Some Content</html>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked contains all DTD tokens
// $unlocked is empty
$parsedHTML->unlock_dtd();
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked is empty
// $unlocked contains all DTD tokens
?>
get_locked_dtd()
Description
array get_locked_dtd ( )
A method of class parseHTML. Returns an array of all locked Document Type Definitions tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked Document Type Definitions tokens.
Examples
<?php
$html = "<!DOCTYPE html ><html>Some Content</html>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked contains all DTD tokens
// $unlocked is empty
$parsedHTML->unlock_dtd();
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked is empty
// $unlocked contains all DTD tokens
?>
get_unlocked_dtd()
Description
array get_unlocked_dtd ( )
A method of class parseHTML. Returns an array of all unlocked Document Type Definitions tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked Document Type Definitions tokens.
Examples
<?php
$html = "<!DOCTYPE html ><html>Some Content</html>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked contains all DTD tokens
// $unlocked is empty
$parsedHTML->unlock_dtd();
$tokens = $parsedHTML->get_dtd();
$locked = $parsedHTML->get_locked_dtd();
$unlocked = $parsedHTML->get_unlocked_dtd();
// at this point:
// $tokens contains all DTD tokens
// $locked is empty
// $unlocked contains all DTD tokens
?>
get_cdata()
Description
array get_cdata ( )
A method of class parseHTML. Returns an array of all CDATA tokens, regardless of locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all CDATA tokens, regardless of locked/unlocked status.
Examples
<?php
$html = "<script><![CDATA[ some script ]]></script>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked contains all CDATA tokens
// $unlocked is empty
$parsedHTML->unlock_cdata();
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked is empty
// $unlocked contains all CDATA tokens
?>
get_locked_cdata()
Description
array get_locked_cdata ( )
A method of class parseHTML. Returns an array of all locked CDATA tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked CDATA tokens.
Examples
<?php
$html = "<script><![CDATA[ some script ]]></script>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked contains all CDATA tokens
// $unlocked is empty
$parsedHTML->unlock_cdata();
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked is empty
// $unlocked contains all CDATA tokens
?>
get_unlocked_cdata()
Description
array get_unlocked_cdata ( )
A method of class parseHTML. Returns an array of all unlocked CDATA tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked CDATA tokens.
Examples
<?php
$html = "<script><![CDATA[ some script ]]></script>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked contains all CDATA tokens
// $unlocked is empty
$parsedHTML->unlock_cdata();
$tokens = $parsedHTML->get_cdata();
$locked = $parsedHTML->get_locked_cdata();
$unlocked = $parsedHTML->get_unlocked_cdata();
// at this point:
// $tokens contains all CDATA tokens
// $locked is empty
// $unlocked contains all CDATA tokens
?>
get_xml()
Description
array get_xml ( )
A method of class parseHTML. Returns an array of all XML Declaration tokens, regardless of locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all XML Declaration tokens, regardless of locked/unlocked status.
Examples
<?php
$html = "<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html >";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked contains all XML Declaration tokens
// $unlocked is empty
$parsedHTML->unlock_xml();
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked is empty
// $unlocked contains all XML Declaration tokens
?>
get_locked_xml()
Description
array get_locked_xml ( )
A method of class parseHTML. Returns an array of all locked XML Declaration tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked XML Declaration tokens.
Examples
<?php
$html = "<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html >";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked contains all XML Declaration tokens
// $unlocked is empty
$parsedHTML->unlock_xml();
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked is empty
// $unlocked contains all XML Declaration tokens
?>
get_unlocked_xml()
Description
array get_unlocked_xml ( )
A method of class parseHTML. Returns an array of all unlocked XML Declaration tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked XML Declaration tokens.
Examples
<?php
$html = "<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html >";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked contains all XML Declaration tokens
// $unlocked is empty
$parsedHTML->unlock_xml();
$tokens = $parsedHTML->get_xml();
$locked = $parsedHTML->get_locked_xml();
$unlocked = $parsedHTML->get_unlocked_xml();
// at this point:
// $tokens contains all XML Declaration tokens
// $locked is empty
// $unlocked contains all XML Declaration tokens
?>
get_text()
Description
array get_text ( )
A method of class parseHTML. Returns an array of all Plain Text tokens, regardless of locked/unlocked status. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all Plain Text tokens, regardless of locked/unlocked status.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked contains all Plain Text tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked is empty
// $unlocked contains all Plain Text tokens
?>
get_locked_text()
Description
array get_locked_text ( )
A method of class parseHTML. Returns an array of all locked Plain Text tokens. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Return Values
Returns an array of all locked Plain Text tokens.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked contains all Plain Text tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked is empty
// $unlocked contains all Plain Text tokens
?>
get_unlocked_text()
Description
array get_unlocked_text ( )
A method of class parseHTML. Returns an array of all unlocked Plain Text tokens. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Return Values
Returns an array of all unlocked Plain Text tokens.
Examples
<?php
$html = "<p>some text</p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked contains all Plain Text tokens
// $unlocked is empty
$parsedHTML->unlock_text();
$tokens = $parsedHTML->get_text();
$locked = $parsedHTML->get_locked_text();
$unlocked = $parsedHTML->get_unlocked_text();
// at this point:
// $tokens contains all Plain Text tokens
// $locked is empty
// $unlocked contains all Plain Text tokens
?>
get_tag_by_id()
Description
array get_tag_by_id ( mixed $idNames )
A method of class parseHTML. Returns an array of HTML Tag (or more precisely: “Element”) tokens — locked or unlocked — with given IDs in a parseHTML instance. This method will return all opening, and self-closing tags; it will not match closing tags. All tokens are locked by default and must be explicitly unlocked prior to modification via the update method.
Parameters
- idNames
- REQUIRED. Accepts either a string of a single tag name, or an array of multiple tag names.
Return Values
Returns an array of all HTML Tag tokens of given IDs. If multiple IDs are passed, this method will return a single array of tokens where each token matches at least one of the provided IDs.
Examples
<?php
$html = "<p id='byline'>some <em>text</em></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tag_by_id('byline');
// $tokens contains HTML Tag token with the ID "byline"
?>
get_children()
Description
array get_children ( string $tagTokens [ , int $tokenType = ALL_TOKENS ] )
A method of class parseHTML. Returns an array of children of the provided HTML Tag tokens in a parseHTML instance. Locked tokens will NOT be overwritten by the update method. All tokens are locked by default.
Parameters
- tagTokens
- REQUIRED. Array of HTML Tag tokens. Tokens must be formatted according to the expected parseHTML format.
- tokenType
- OPTIONAL. Defines the type of tokens that should be returned. Default is ALL_TOKENS. Allowed values are:
- ALL_TOKENS (default)
- TEXT_TOKENS
- TAG_TOKENS
- COMMENT_TOKENS
- CDATA_TOKENS
- TEXT_AND_TAG_TOKENS
- TEXT_AND_COMMENT_TOKENS
- TEXT_AND_CDATA_TOKENS
- TAG_AND_COMMENT_TOKENS
- TAG_AND_CDATA_TOKENS
- COMMENT_AND_CDATA_TOKENS
- TEXT_TAG_AND_COMMENT_TOKENS
- TEXT_TAG_AND_CDATA_TOKENS
- TEXT_COMMENT_AND_CDATA_TOKENS
- TAG_COMMENT_AND_CDATA_TOKENS
Return Values
Returns an array of children of the provided HTML Tag tokens
Examples
<?php
$html = "<p id='byline'>some <em>text</em></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$idTokens = $parsedHTML->get_tag_by_id('byline');
$tokens = $parsedHTML->get_children($idTokens, TEXT_TOKENS);
// $tokens contains all Plain Text children tokens of ID "byline"
?>

