parseHTML (un)Lock 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 Load Methods

return to top

lock()

Descrip­tion

bool lock ( string $tokens )

A method of class parse­HTML. Locks all passed 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

tokens
REQUIRED. Array of tokens. Tokens must be for­mat­ted accord­ing to the expected parse­HTML for­mat. Gen­er­ally, tokens are acquired from a parse­HTML instance using one of the many pro­vided get meth­ods.

Return Val­ues

Returns TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$tags = $parsedHTML->get_tags();
$parsedHTML->unlock($tokens);
$parsedHTML->lock($tags);
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p></p>
?>

return to top

unlock()

Descrip­tion

bool unlock ( string $tokens )

A method of class parse­HTML. Unlocks all passed tokens in a parse­HTML instance. 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

tokens
REQUIRED. Array of tokens. Tokens must be for­mat­ted accord­ing to the expected parse­HTML for­mat. Gen­er­ally, tokens are acquired from a parse­HTML instance using one of the many pro­vided get meth­ods.

Return Val­ues

Returns TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$tags = $parsedHTML->get_tags();
$parsedHTML->unlock($tokens);
$parsedHTML->lock($tags);
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p></p>
?>

return to top

lock_​comments()

Descrip­tion

bool lock_comments ( )

A method of class parse­HTML. Locks all HTML Com­ment tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns TRUE upon success;

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_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_comments();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <!-- a comment -->
?>

return to top

unlock_​comments()

Descrip­tion

bool unlock_comments ( )

A method of class parse­HTML. Unlocks all HTML Com­ment tokens in a parse­HTML instance. 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 TRUE upon success;

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_all();
$parsedHTML->unlock_comments();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p>some text</p>
?>

return to top

lock_​dtd()

Descrip­tion

bool lock_dtd ( )

A method of class parse­HTML. Locks all Doc­u­ment Type Def­i­n­i­tion tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns TRUE upon success;

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_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_dtd();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <!DOCTYPE html >
?>

return to top

unlock_​dtd()

Descrip­tion

bool unlock_dtd ( )

A method of class parse­HTML. Unlocks all Doc­u­ment Type Def­i­n­i­tion tokens in a parse­HTML instance. 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 TRUE upon success;

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_all();
$parsedHTML->unlock_dtd();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <html>Some Content</html>
?>

return to top

lock_​cdata()

Descrip­tion

bool lock_cdata ( )

A method of class parse­HTML. Locks all CDATA tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns TRUE upon success;

Exam­ples


<?php
$html = "<script><![CDATA[ some script ]]></script>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_cdata();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <![CDATA[ some script ]]>
?>

return to top

unlock_​cdata()

Descrip­tion

bool unlock_cdata ( )

A method of class parse­HTML. Unlocks all CDATA tokens in a parse­HTML instance. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method. Given that CDATA’s pur­pose is to pro­tect its con­tent from pars­ing, we do not know why any­one would use this method, but it is here regardless.

Return Val­ues

Returns TRUE upon success;

Exam­ples


<?php
$html = "<script><![CDATA[ some script ]]></script>";

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock_cdata();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <script></script>
?>

return to top

lock_​xml()

Descrip­tion

bool lock_xml ( )

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

Return Val­ues

Returns TRUE upon success;

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_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_xml();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <?xml version="1.0" encoding="UTF-8"?>
?>

return to top

unlock_​xml()

Descrip­tion

bool unlock_xml ( )

A method of class parse­HTML. Unlocks all XML Dec­la­ra­tion tokens in a parse­HTML instance. 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 TRUE upon success;

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_all();
$parsedHTML->unlock_xml();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <!DOCTYPE html >
?>

return to top

lock_​tags()

Descrip­tion

bool lock_tags ( [ int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Locks all HTML Tag (or more pre­cisely: “Ele­ment”) tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default. NOTE: this method does not lock tokens related to the chil­dren of these HTML Tags (except­ing con­tained HTML Tags). For that func­tion­al­ity, please see the lock_​children() method.

Para­me­ters

tag­Type
OPTIONAL. Defines what type of tags should be locked. 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 TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_tags();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p></p>
?>

return to top

unlock_​tags()

Descrip­tion

bool unlock_tags ( [ int $tagType = ALL_TAGS ] )

A method of class parse­HTML. Unlocks all HTML Tag (or more pre­cisely: “Ele­ment”) tokens in a parse­HTML instance. All tokens are locked by default and must be explic­itly unlocked prior to mod­i­fi­ca­tion via the update method. NOTE: this method does not unlock tokens related to the chil­dren of these HTML Tags (except­ing con­tained HTML Tags). For that func­tion­al­ity, please see the unlock_​children() method.

Para­me­ters

tag­Type
OPTIONAL. Defines what type of tags should be unlocked. 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 TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock_tags();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // some content
?>

return to top

lock_​text()

Descrip­tion

bool lock_text ( )

A method of class parse­HTML. Locks all Plain Text tokens in a parse­HTML instance. Locked tokens will NOT be over­writ­ten by the update method. All tokens are locked by default.

Return Val­ues

Returns TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_text();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // some content
?>

return to top

unlock_​text()

Descrip­tion

bool unlock_text ( )

A method of class parse­HTML. Unlocks all Plain Text tokens in a parse­HTML instance. 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 TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$parsedHTML->unlock_text();
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p></p>
?>

return to top

lock_​children()

Descrip­tion

bool lock_children ( string $tagTokens [ , int $tokenType = ALL_TOKENS ] )

A method of class parse­HTML. Locks all 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 for­mat. Gen­er­ally, tokens are acquired from a parse­HTML instance using one of the many pro­vided get meth­ods.
token­Type
OPTIONAL. Defines the type of tokens that should be locked. 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 TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$tags = $parsedHTML->get_tags();
$parsedHTML->unlock($tokens);
$parsedHTML->lock_children($tags);
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // some content
?>

return to top

unlock_​children()

Descrip­tion

bool unlock_children ( string $tagTokens [ , int $tokenType = ALL_TOKENS ] )

A method of class parse­HTML. Unlocks all chil­dren of the pro­vided HTML Tag tokens in a parse­HTML instance. 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­To­kens
REQUIRED. Array of HTML Tag tokens. Tokens must be for­mat­ted accord­ing to the expected parse­HTML for­mat. Gen­er­ally, tokens are acquired from a parse­HTML instance using one of the many pro­vided get meth­ods.
token­Type
OPTIONAL. Defines the type of tokens that should be locked. 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 TRUE upon success;

Exam­ples


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

include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$tokens = $parsedHTML->get_all();
$tags = $parsedHTML->get_tags();
$parsedHTML->unlock_children($tags);
foreach($tokens as &$token) {
	$tokens["value"] = ""; // clears value
}
$parsedHTML->update($tokens);
$html = $parsedHTML->unload();

echo $html; // <p></p>
?>

return to top