コード例 #1
0
 /**
  * Create a html element.
  *
  * @param string $name    Element tag name.
  * @param mixed  $content Element content.
  * @param array  $attribs Element attributes.
  *
  * @return  string Created element string.
  */
 public static function create($name, $content = '', $attribs = array())
 {
     $name = trim($name);
     $unpaired = in_array(strtolower($name), static::$unpairedElements);
     $tag = '<' . $name;
     foreach ((array) $attribs as $key => $value) {
         if ($value !== null && $value !== false && $value !== '') {
             $tag .= ' ' . $key . '=' . String::quote($value, '""');
         }
     }
     if ($content) {
         if (!$content instanceof HtmlElement) {
             $content = implode(PHP_EOL, (array) $content);
         }
         $tag .= '>' . PHP_EOL . "\t" . $content . PHP_EOL . '</' . $name . '>';
     } else {
         $tag .= $unpaired ? ' />' : '></' . $name . '>';
     }
     return $tag;
 }