本文整理匯總了PHP中DOMNode::hasChildren方法的典型用法代碼示例。如果您正苦於以下問題:PHP DOMNode::hasChildren方法的具體用法?PHP DOMNode::hasChildren怎麽用?PHP DOMNode::hasChildren使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DOMNode
的用法示例。
在下文中一共展示了DOMNode::hasChildren方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addQuotesAndStripTags
/**
* convert blockquotes to quotes ("> ") and strip tags
*
* this function uses tidy or DOM to recursivly walk the dom tree of the html mail
* @see http://php.net/manual/de/tidy.root.php
* @see http://php.net/manual/en/book.dom.php
*
* @param tidyNode|DOMNode $_node
* @param integer $_quoteIndent
* @param string $_eol
* @return string
*
* @todo we can transform more tags here, i.e. the <strong>BOLDTEXT</strong> tag could be replaced with *BOLDTEXT*
* @todo think about removing the tidy code
* @todo reduce complexity
*/
public static function addQuotesAndStripTags($_node, $_quoteIndent = 0, $_eol = "\n")
{
$result = '';
$hasChildren = $_node instanceof DOMNode ? $_node->hasChildNodes() : $_node->hasChildren();
$nameProperty = $_node instanceof DOMNode ? 'nodeName' : 'name';
$valueProperty = $_node instanceof DOMNode ? 'nodeValue' : 'value';
$divNewline = FALSE;
if ($hasChildren) {
$lastChild = NULL;
$children = $_node instanceof DOMNode ? $_node->childNodes : $_node->child;
if ($_node->{$nameProperty} == 'div') {
$divNewline = TRUE;
}
foreach ($children as $child) {
$isTextLeaf = $child instanceof DOMNode ? $child->{$nameProperty} == '#text' : !$child->{$nameProperty};
if ($isTextLeaf) {
// leaf -> add quotes and append to content string
if ($_quoteIndent > 0) {
$result .= str_repeat(self::QUOTE, $_quoteIndent) . $child->{$valueProperty};
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
}
if ($divNewline) {
$result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
$divNewline = FALSE;
}
$result .= $child->{$valueProperty};
}
} else {
if ($child->{$nameProperty} == 'blockquote') {
// opening blockquote
$_quoteIndent++;
} else {
if ($child->{$nameProperty} == 'br') {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
}
// reset quoted state on newline
if ($lastChild !== NULL && $lastChild->{$nameProperty} == 'br') {
// add quotes to repeating newlines
$result .= str_repeat(self::QUOTE, $_quoteIndent);
}
$result .= $_eol;
$divNewline = FALSE;
}
}
}
$result .= self::addQuotesAndStripTags($child, $_quoteIndent, $_eol);
if ($child->{$nameProperty} == 'blockquote') {
// closing blockquote
$_quoteIndent--;
// add newline after last closing blockquote
if ($_quoteIndent == 0) {
$result .= $_eol;
}
}
$lastChild = $child;
}
// add newline if closing div
if ($divNewline) {
$result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
}
}
return $result;
}