This function will help you if you have some HTML table(for example the description of something) when you need to show same data in different places-structures.It crops table rows based on how many rows to leave.My practical application of this was when I had description of product on some page, in product details I showed full table with all rows, and in products list i showed only first three rows of same table.I hope someone helps.Greetz!!! 8)
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
' . $html;
$dom = new DOMDocument('1.0', 'windows-1250');
$dom->substituteEntities = true;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
//We get the tag element we want to be removed
$elements = $dom->getElementsByTagName('tr');
//We put all elements in array
$tags = array();
foreach($elements as $tag) {
$tags[] = $tag;
}
//If we for example don't want to remove first 2-3 rows, we pass the parametar row
//for how many rows to leave from top(this can be reversed to begin from down of course)
for ($i=0; $i<=$rows-1; $i++){
unset($tags[$i]);
}
//We remove the remaining rows
foreach($tags as $tag) {
$tag->parentNode->removeChild($tag);
}
$html = $dom->saveHTML();
return $html;
}
//Generate the table
$some_html_table = '
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)