if (!isset($elements)) { $elements = 2; } // Get just the text (no markup) from a node using $node->textContent. // Compare the textContent value to the one returned by $node->nodeValue. libxml_use_internal_errors(true); $dom = new DomDocument(); $dom->preserveWhiteSpace = false; $dom->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $this->Body . '</body></html>'); $dom->normalize(); $nodes = $dom->getElementsByTagName("body")->item(0)->childNodes; $elementCount = 0; $this->preview = ''; foreach ($nodes as $node) { if ($node->nodeType === XML_ELEMENT_NODE) { $this->preview .= $dom->saveXML($node); $elementCount++; if ($elementCount === $elements) { break; } } } // Carriage returns in the XML prevent the markup from validating. -- cwells $this->preview = str_replace(' ', '', $this->preview); } return $this->preview; } } /* Database mappings: instantiated outside the class definition because they're static. */ BlogPost::addDatabaseMapping('Tags', new DatabaseMapping(DatabaseMapping::ManyToMany, 'ID', 'BlogPost_Tag.BlogPostID', array(new DatabaseMapping(DatabaseMapping::ManyToMany, 'BlogPost_Tag.TagID', 'Tag.ID'))));