本文整理汇总了PHP中Element::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::addChild方法的具体用法?PHP Element::addChild怎么用?PHP Element::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element::addChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createElement
private static function createElement($seletor, $data)
{
if (preg_match('/^\\{(.+)\\}$/is', trim($seletor), $content)) {
return new TextElement(self::replaceVars($content[1], $data));
}
if (preg_match_all('/([a-z0-9]+)(#[^\\.\\[\\{]+)?(\\.[^\\[\\{]+)?(\\[.+\\])?(?:\\{(.+)\\})?/is', $seletor, $matches, PREG_SET_ORDER)) {
/*
* 1 - tagName
* 2 - id
* 3 - classes
* 4 - attributes
* 5 - content
* */
$matches = $matches[0];
$htmlTag = $matches[1];
$element = new Element($htmlTag, null, self::isEmptyTag($htmlTag));
if (isset($matches[2]) && !empty($matches[2])) {
$element->attr('id', trim($matches[2], '#'));
}
if (isset($matches[3]) && !empty($matches[3])) {
$classes = implode(' ', explode('.', trim($matches[3], '.')));
$element->attr('class', $classes);
}
if (isset($matches[4]) && !empty($matches[4])) {
if (!preg_match_all('/\\[([^=]+)=(.*?)\\]/is', $matches[4], $attrs, PREG_SET_ORDER)) {
return null;
}
foreach ($attrs as $attr) {
$value = self::replaceVars($attr[2], $data);
$element->attr($attr[1], $value);
}
}
if (isset($matches[5]) && !empty($matches[5])) {
$content = self::replaceVars($matches[5], $data);
$element->addChild(new TextElement($content));
}
return $element;
}
return null;
}
示例2: addElementsInOl
protected function addElementsInOl($arr)
{
$li = new Element('li');
foreach ($arr as $el) {
$li->addChild($el);
}
$this->ol->addChild($li);
}
示例3: parseBody
public function parseBody(Element $node)
{
$nodeName = $node->getName();
do {
if ($this->current() != "<" || $nodeName == "script" && !$this->equal("</script>")) {
$text = "";
while ($this->current() != "<" || $nodeName == "script" && !$this->equal("</script>")) {
$text .= $this->current();
$this->next();
}
if (trim($text)) {
$textNode = new Text($text);
$node->addChild($textNode);
}
} elseif ($this->current() == "<" && $this->getNext() != "/") {
$childNode = $this->parseNode();
$node->addChild($childNode);
} else {
$this->next(2);
$endName = $this->parseName();
if ($endName != $nodeName) {
echo "unexpected end of '{$endName}', {$nodeName} expected at {$this->ccline}:{$this->ccpos}\n";
$this->back(strlen("</{$endName}"));
} else {
$this->skipWhiteSpaces();
$this->next();
}
break;
}
} while (true);
}