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 Load Methods
in_tag()
Description
bool in_tag ( mixed $tagNames , array $token )
A method of class parseHTML. Tests whether token is a child of one of the specified HTML elements.
Parameters
- tagNames
- REQUIRED. A string or array of HTML element name(s).
- token
- REQUIRED. Array of a single token. Token must be formatted according to the expected parseHTML format. Generally, tokens are acquired from a parseHTML instance using one of the many provided get methods.
Return Values
Returns TRUE if the provided token is a child of at least one of the specified tagNames, FALSE if it is not.
Examples
<?php
$html = "<p>some <span>text</span></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$parsedHTML->unlock_text();
$unlockedTexts = $parsedHTML->get_unlocked_text();
foreach($unlockedTexts as &$unlockedText) {
// do something here like... SHOUT!
if($parsedHTML->in_tag('span', $unlockedText)):
$unlockedText["value"] = strtoupper($unlockedText["value"]);
endif;
}
$parsedHTML->update($unlockedTexts);
$html = $parsedHTML->unload();
echo $html; // <p>some <span>TEXT</span></p>
?>
in_id()
Description
bool in_id ( mixed $idNames , array $token )
A method of class parseHTML. Tests whether token is a child of an HTML element of a given ID.
Parameters
- idNames
- REQUIRED. A string or array of ID name(s) for HTML elements.
- token
- REQUIRED. Array of a single token. Token must be formatted according to the expected parseHTML format. Generally, tokens are acquired from a parseHTML instance using one of the many provided get methods.
Return Values
Returns TRUE if the provided token is a child of at least one HTML element of a given ID, FALSE if it is not.
Examples
<?php
$html = "<p>some <span id="foo">text</span></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$parsedHTML->unlock_text();
$unlockedTexts = $parsedHTML->get_unlocked_text();
foreach($unlockedTexts as &$unlockedText) {
// do something here like... SHOUT!
if($parsedHTML->in_id('foo', $unlockedText)):
$unlockedText["value"] = strtoupper($unlockedText["value"]);
endif;
}
$parsedHTML->update($unlockedTexts);
$html = $parsedHTML->unload();
echo $html; // <p>some <span id="foo">TEXT</span></p>
?>
in_class()
Description
bool in_class ( mixed $classNames , array $token )
A method of class parseHTML. Tests whether token is a child of an HTML element of a given class name.
Parameters
- classNames
- REQUIRED. A string or array of class name(s) for HTML elements.
- token
- REQUIRED. Array of a single token. Token must be formatted according to the expected parseHTML format. Generally, tokens are acquired from a parseHTML instance using one of the many provided get methods.
Return Values
Returns TRUE if the provided token is a child of at least one HTML element of a given class, FALSE if it is not.
Examples
<?php
$html = "<p>some <span class="foo">text</span></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$parsedHTML->unlock_text();
$unlockedTexts = $parsedHTML->get_unlocked_text();
foreach($unlockedTexts as &$unlockedText) {
// do something here like... SHOUT!
if($parsedHTML->in_class('foo', $unlockedText)):
$unlockedText["value"] = strtoupper($unlockedText["value"]);
endif;
}
$parsedHTML->update($unlockedTexts);
$html = $parsedHTML->unload();
echo $html; // <p>some <span class="foo">TEXT</span></p>
?>
in_attribute()
Description
bool in_attribute ( string $attributeName , mixed $attributeValues , array $token )
A method of class parseHTML. Tests whether token is a child of an HTML element with an attribute of a given value.
Parameters
- attributeName
- REQUIRED. A string of the name of an HTML element attribute.
- attributeValues
- REQUIRED. A string or array of values for the specified HTML element attribute.
- token
- REQUIRED. Array of a single token. Token must be formatted according to the expected parseHTML format. Generally, tokens are acquired from a parseHTML instance using one of the many provided get methods.
Return Values
Returns TRUE if the provided token is a child of at least one HTML element with an attribute of specific value, FALSE if it is not.
Examples
<?php
$html = "<p>some <span title="foo">text</span></p>";
include('path/to/php-parser.php');
$parsedHTML = new parseHTML();
$parsedHTML->load($html);
$parsedHTML->unlock_text();
$unlockedTexts = $parsedHTML->get_unlocked_text();
foreach($unlockedTexts as &$unlockedText) {
// do something here like... SHOUT!
if($parsedHTML->in_attribute('title', 'foo', $unlockedText)):
$unlockedText["value"] = strtoupper($unlockedText["value"]);
endif;
}
$parsedHTML->update($unlockedTexts);
$html = $parsedHTML->unload();
echo $html; // <p>some <span title="foo">TEXT</span></p>
?>

