parseHTML Get Methods

This draft of the doc­u­men­ta­tion remains imma­ture. While we have made attempt to be thor­ough and accu­rate, you may encounter errors. If you dis­cover any defi­cien­cies, please let us know at info@​kingdesk.​com

This page is a sub­set of the doc­u­men­ta­tion of the func­tion­al­ity pro­vided by the PHP Parser project.

parse­HTML Get Methods

return to top

get_​all()

Descrip­tion

array get_all ( )

A method of class parse­HTML. Returns an array of all tokens, regard­less of type or locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all tokens, regard­less of type or locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked()

Descrip­tion

array get_locked ( )

A method of class parse­HTML. Returns an array of all locked tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked tokens, regard­less of type.

Exam­ples


<?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
?>

return to top

get_​unlocked()

Descrip­tion

array get_unlocked ( )

A method of class parse­HTML. Returns an array of all unlocked tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked tokens, regard­less of type.

Exam­ples


<?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
?>

return to top

get_​comments()

Descrip­tion

array get_comments ( )

A method of class parse­HTML. Returns an array of all HTML Com­ment tokens, regard­less of locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all HTML Com­ment tokens, regard­less of locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked_​comments()

Descrip­tion

array get_locked_comments ( )

A method of class parse­HTML. Returns an array of all locked HTML Com­ment tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked HTML Com­ment tokens.

Exam­ples


<?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
?>

return to top

get_​unlocked_​comments()

Descrip­tion

array get_unlocked_comments ( )

A method of class parse­HTML. Returns an array of all unlocked HTML Com­ment tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked HTML Com­ment tokens.

Exam­ples


<?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
?>

return to top

get_​dtd()

Descrip­tion

array get_dtd ( )

A method of class parse­HTML. Returns an array of all Doc­u­ment Type Def­i­n­i­tions tokens, regard­less of locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all Doc­u­ment Type Def­i­n­i­tions tokens, regard­less of locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked_​dtd()

Descrip­tion

array get_locked_dtd ( )

A method of class parse­HTML. Returns an array of all locked Doc­u­ment Type Def­i­n­i­tions tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked Doc­u­ment Type Def­i­n­i­tions tokens.

Exam­ples


<?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
?>

return to top

get_​unlocked_​dtd()

Descrip­tion

array get_unlocked_dtd ( )

A method of class parse­HTML. Returns an array of all unlocked Doc­u­ment Type Def­i­n­i­tions tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked Doc­u­ment Type Def­i­n­i­tions tokens.

Exam­ples


<?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
?>

return to top

get_​cdata()

Descrip­tion

array get_cdata ( )

A method of class parse­HTML. Returns an array of all CDATA tokens, regard­less of locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all CDATA tokens, regard­less of locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked_​cdata()

Descrip­tion

array get_locked_cdata ( )

A method of class parse­HTML. Returns an array of all locked CDATA tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked CDATA tokens.

Exam­ples


<?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
?>

return to top

get_​unlocked_​cdata()

Descrip­tion

array get_unlocked_cdata ( )

A method of class parse­HTML. Returns an array of all unlocked CDATA tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked CDATA tokens.

Exam­ples


<?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
?>

return to top

get_​xml()

Descrip­tion

array get_xml ( )

A method of class parse­HTML. Returns an array of all XML Dec­la­ra­tion tokens, regard­less of locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all XML Dec­la­ra­tion tokens, regard­less of locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked_​xml()

Descrip­tion

array get_locked_xml ( )

A method of class parse­HTML. Returns an array of all locked XML Dec­la­ra­tion tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked XML Dec­la­ra­tion tokens.

Exam­ples


<?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
?>

return to top

get_​unlocked_​xml()

Descrip­tion

array get_unlocked_xml ( )

A method of class parse­HTML. Returns an array of all unlocked XML Dec­la­ra­tion tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked XML Dec­la­ra­tion tokens.

Exam­ples


<?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
?>

return to top

get_​tags()

Descrip­tion

array get_tags ( [ int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of HTML Tag (or more pre­cisely: “Ele­ment”) tokens — locked or unlocked — in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to ALL_​TAGS. Accepts the fol­low­ing constants:
  • ALL_​TAGS (default)
  • OPENING_​TAGS
  • CLOSING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS
  • SELFCLOSING_​AND_​CLOSING_​TAGS
  • OPENING_​AND_​CLOSING_​TAGS

Return Val­ues

Returns an array of all match­ing HTML Tag tokens.

Exam­ples


<?php
$html = "<p>some text</p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked contains all HTML Tag tokens
//	$unlocked is empty

$parsedHTML->unlock_tags();
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked is empty
//	$unlocked contains all HTML Tag tokens
?>

return to top

get_​locked_​tags()

Descrip­tion

array get_locked_tags ( [ int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of locked HTML Tag (or more pre­cisely: “Ele­ment”) tokens in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to ALL_​TAGS. Accepts the fol­low­ing constants:
  • ALL_​TAGS (default)
  • OPENING_​TAGS
  • CLOSING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS
  • SELFCLOSING_​AND_​CLOSING_​TAGS
  • OPENING_​AND_​CLOSING_​TAGS

Return Val­ues

Returns an array of all locked match­ing HTML Tag tokens.

Exam­ples


<?php
$html = "<p>some text</p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked contains all HTML Tag tokens
//	$unlocked is empty

$parsedHTML->unlock_tags();
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked is empty
//	$unlocked contains all HTML Tag tokens
?>

return to top

get_​unlocked_​tags()

Descrip­tion

array get_unlocked_tags ( [ int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of unlocked HTML Tag (or more pre­cisely: “Ele­ment”) tokens in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to ALL_​TAGS. Accepts the fol­low­ing constants:
  • ALL_​TAGS (default)
  • OPENING_​TAGS
  • CLOSING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS
  • SELFCLOSING_​AND_​CLOSING_​TAGS
  • OPENING_​AND_​CLOSING_​TAGS

Return Val­ues

Returns an array of all unlocked match­ing HTML Tag tokens.

Exam­ples


<?php
$html = "<p>some text</p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked contains all HTML Tag tokens
//	$unlocked is empty

$parsedHTML->unlock_tags();
$tokens = $parsedHTML->get_tags();
$locked = $parsedHTML->get_locked_tags();
$unlocked = $parsedHTML->get_unlocked_tags();

// at this point:
//	$tokens contains all HTML Tag tokens
//	$locked is empty
//	$unlocked contains all HTML Tag tokens
?>

return to top

get_​text()

Descrip­tion

array get_text ( )

A method of class parse­HTML. Returns an array of all Plain Text tokens, regard­less of locked/​unlocked sta­tus. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all Plain Text tokens, regard­less of locked/​unlocked status.

Exam­ples


<?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
?>

return to top

get_​locked_​text()

Descrip­tion

array get_locked_text ( )

A method of class parse­HTML. Returns an array of all locked Plain Text tokens. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns an array of all locked Plain Text tokens.

Exam­ples


<?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
?>

return to top

get_​unlocked_​text()

Descrip­tion

array get_unlocked_text ( )

A method of class parse­HTML. Returns an array of all unlocked Plain Text tokens. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Return Val­ues

Returns an array of all unlocked Plain Text tokens.

Exam­ples


<?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
?>

return to top

get_​tags_​by_​name()

Descrip­tion

array get_tags_by_name ( mixed $tagNames [ , int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of HTML Tag (or more pre­cisely: “Ele­ment”) tokens — locked or unlocked — with given tag names in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

tag­Names
REQUIRED. Accepts either a string of a sin­gle tag name, or an array of mul­ti­ple tag names.
tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to ALL_​TAGS. Accepts the fol­low­ing constants:
  • ALL_​TAGS (default)
  • OPENING_​TAGS
  • CLOSING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS
  • SELFCLOSING_​AND_​CLOSING_​TAGS
  • OPENING_​AND_​CLOSING_​TAGS

Return Val­ues

Returns an array of all HTML Tag tokens of given tag names. If mul­ti­ple tag names are passed, this method will return a sin­gle array of tokens where each token matches at least one of the pro­vided tag names.

Exam­ples


<?php
$html = "<p>some <em>text</em></p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags_by_name('em', OPENING_TAGS);

//	$tokens contains all opening "em" HTML Tag tokens
?>

return to top

get_​tag_​by_​id()

Descrip­tion

array get_tag_by_id ( mixed $idNames )

A method of class parse­HTML. Returns an array of HTML Tag (or more pre­cisely: “Ele­ment”) tokens — locked or unlocked — with given IDs in a parse­HTML instance. This method will return all open­ing, and self-​​closing tags; it will not match clos­ing tags. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

idNames
REQUIRED. Accepts either a string of a sin­gle tag name, or an array of mul­ti­ple tag names.

Return Val­ues

Returns an array of all HTML Tag tokens of given IDs. If mul­ti­ple IDs are passed, this method will return a sin­gle array of tokens where each token matches at least one of the pro­vided IDs.

Exam­ples


<?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"
?>

return to top

get_​tags_​by_​class()

Descrip­tion

array get_tags_by_class ( mixed $classNames [ , int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of HTML Tag (or more pre­cisely: “Ele­ment”) tokens — locked or unlocked — with given class names in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

class­Names
REQUIRED. Accepts either a string of a sin­gle class name, or an array of mul­ti­ple class names.
tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to OPENING_​AND_​SELFCLOSING_​TAGS. Accepts the fol­low­ing constants:
  • OPENING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS (default)

Return Val­ues

Returns an array of all HTML Tag tokens of given class names. If mul­ti­ple class names are passed, this method will return a sin­gle array of tokens where each token matches at least one of the pro­vided class names.

Exam­ples


<?php
$html = "<p class='alert'>some <em>text</em></p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags_by_class('alert');

//	$tokens contains all HTML Tag tokens of class "alert"
?>

return to top

get_​tags_​by_​attribute()

Descrip­tion

array get_tags_by_attribute ( string $attribute,  mixed $attributeValues [ , int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Returns an array of HTML Tag (or more pre­cisely: “Ele­ment”) tokens — locked or unlocked — with given attribute match­ing given val­ues in a parse­HTML instance. This method will return just open­ing, clos­ing or self-​​closing tags (or any com­bi­na­tion thereof). All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method.

Para­me­ters

attribute
REQUIRED. Accepts a string of a sin­gle attribute type (i.e. “href”, “title”, “rel”…).
attrib­ut­e­Val­ues
REQUIRED. Accepts either a string of a sin­gle attribute value, or an array of mul­ti­ple attribute values.
tag­Type
OPTIONAL. Defines what type of tags should be returned. Defaults to OPENING_​AND_​SELFCLOSING_​TAGS. Accepts the fol­low­ing constants:
  • OPENING_​TAGS
  • SELFCLOSING_​TAGS
  • OPENING_​AND_​SELFCLOSING_​TAGS (default)

Return Val­ues

Returns an array of all HTML Tag tokens with a given attribute match­ing given val­ues. If mul­ti­ple attribute val­ues are passed, this method will return a sin­gle array of tokens where each token matches at least one of the pro­vided attribute values.

Exam­ples


<?php
$html = "<p>some <abbr title='text'>txt.</abbr></p>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_tags_by_attribute('title', "text');

//	$tokens contains all HTML Tag tokens with attribute "title" equal to "text"
?>

return to top

get_​children()

Descrip­tion

array get_children ( string $tagTokens [ , int $tokenType = ALL_TOKENS ] )

A method of class parse­HTML. Returns an array of chil­dren of the pro­vided HTML Tag tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Para­me­ters

tag­To­kens
REQUIRED. Array of HTML Tag tokens. Tokens must be for­mat­ted accord­ing to the expected parse­HTML format.
token­Type
OPTIONAL. Defines the type of tokens that should be returned. Default is ALL_​TOKENS. Allowed val­ues 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 Val­ues

Returns an array of chil­dren of the pro­vided HTML Tag tokens

Exam­ples


<?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"
?>

return to top