定制 theaomx/htmlnode 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

theaomx/htmlnode

Composer 安装命令:

composer require theaomx/htmlnode

包简介

Create custom HTML-Markup by constructing AST-Node-Trees with an easy-to-use HtmlBuilder that implements the builder pattern.

README 文档

README

This is a project that allows you to represent arbritary HTML-AST-Node-Trees in your PHP-Code. This is useful for several reasons. If you use these classes in your projects you are working on trees of nodes instead of strings. Therefore you can pass these instances from one method to another and manipulate the trees directly. Only if the root of the tree or another part of the tree is printed with echo or print then the tree gets converted into the right HTML-Tags. Please take a look at the index.php that creates a sample website and you can see the relevant api-calls there.

simple example which creates an HTML5 barebone website

use \TheAomx\Nodes\HtmlNode as HtmlNode;
use \TheAomx\Nodes\Indentation as Indentation;

$html = HtmlNode::get_builder("html")->attr("lang", "de")->build();

$head = HtmlNode::get_builder("head")->build();
$charset = HtmlNode::get_builder("meta")->attr("charset", "utf-8")->build();
$viewport = HtmlNode::get_builder("meta")->attr("name", "viewport")->
                attr("content", "width=device-width, initial-scale=1.0")->build();
$title = HtmlNode::get_builder("title")->text("Hello World Site")->build();
$head->addChildNode($charset)->addChildNode($viewport)->addChildNode($title);

$body = HtmlNode::get_builder("body")->build();
$html->append($head)->append($body);

$h1 = HtmlNode::get_builder("h1")->text("Welcome stranger!")->build();
$p = HtmlNode::get_builder("p")->attr("style", "color: red;")->
                attribute("align", "left")->build();
$b = HtmlNode::get_builder("b")->s_text("Hello World with umlaute äöü&%")->build();
$p->append($b);

$body->append($h1)->append($p);

// only at this step the root ast-node $html gets converted to a string!
echo $html;

The resulting html of the above example would be like this. If you want you can disable the pretty printing of the html output, such that no blank lines or spaces have to be transferred.

<html lang="de">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>
      Hello World Site
    </title>
  </head>
  <body>
    <h1>
      Welcome stranger!
    </h1>
    <p style="color: red;" align="left">
      <b>
        Hello World with umlaute &auml;&ouml;&uuml;&amp;%
      </b>
    </p>
  </body>
</html>

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固