geeklab/html

为 PHP 5.3+ 编程创建 HTML (XHTML, 4.x, 5)

1.0.3 2017-04-28 02:10 UTC

This package is auto-updated.

Last update: 2024-09-28 22:36:29 UTC


README

为 PHP 5.3+ 编程创建 HTML (HTML, 4.x, 5)

待办事项

  • 添加 HTML 4.x 和 5 支持
  • 更多方法
  • API 文档

功能

  • 编程创建 (X)HTML

安装

将 src\ 文件夹复制到 GeekLab\HTML 文件夹,以便您的自动加载器可以加载它。

- 或者 -

通过 Composer

composer.json

{
    "require":
    {
        "geeklab/html": "*"
    }
    "minimum-stability": "dev"
}

用法(从 example\index.php)

/**
 * XHTML 1.0 Transitional, Language "en" and encoding of "UTF-8" no indention
 */
//$HTML = new GeekLab\HTML\HTML();

/**
 * XHTML 1.0 Transitional, Language "en" and encoding of "UTF-8" with indention
 */
//$HTML = new GeekLab\HTML\HTML(array('indent' => TRUE));

/**
 * XHTML 1.0 Strict, Language "en" and encoding of "UTF-8" with indention
 */
//$HTML = new GeekLab\HTML\HTML(array('indent' => TRUE, 'level' => 'strict')) ;

/**
 * XHTML 1.0 Strict, Language "fr" and encoding of "ISO-8859-1" with indention
 */
//$HTML = new GeekLab\HTML\HTML(array('indent' => TRUE, 'level' => 'strict', 'lang' => 'fr', 'encoding' => 'ISO-8859-1')) ;

/**
 * XHTML 1.1, Language "en" and encoding of "UTF-8" with indention
 */
//$HTML = new GeekLab\HTML\HTML(array('indent' => TRUE, 'version' => '1.1')) ;

/**
 * HTML 4.01, Language "en" with indention
 **/
//$HTML = new GeekLab\HTML(array('indent' => TRUE, 'docType' => 'html', 'version' => '4.01'));

/**
 * HTML5, Language "en" with indention
 */
$HTML = new GeekLab\HTML\HTML(array('indent' => TRUE, 'docType' => 'html', 'version' => '5'));

$HTML->open('head') // Create the head tag
     ->open('title', 'HTML Test') // Create the title tag with text
     ->close(2); // Close the previous 2 html tags

$HTML->open('body') // Create the body tag
     ->openClose('h1', 'Hello Wold') // Create and close an H1 tag with text
     ->openClose('hr') // Create and close an HR tag
     ->open('div', '', array('id' => 'myDiv')) // Create a div tag with an ID of 'myDiv'
     ->open('p') // Create a P tag
     ->addText('Testing 123!') // Add some text
     ->closeAll(); // Close all open tags.

echo $HTML->output(TRUE); // Out HTML wrapped with DOCType and HTML tags.

API