承接 marwanalsoltany/php-html 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

marwanalsoltany/php-html

最新稳定版本:v1.0.0

Composer 安装命令:

composer require marwanalsoltany/php-html

包简介

A fluent interface for creating HTML using PHP.

README 文档

README

PHP-HTML

A fluent interface for creating HTML using PHP.

PHP Version Latest Version on Packagist Total Downloads License Maintenance Documentation
GitHub Continuous Integration GitHub Continuous Deployment Codecov

Open in Visual Studio Code

Tweet Star

Table of Contents

About
Installation
Examples
More
Changelog


If you like this project and would like to support its development, giving it a ⭐ would be appreciated!

Installation

Using Composer:

Install PHP-HTML through Composer using:

composer require marwanalsoltany/php-html

Why Does This Exist?

Why not?

This is something that I exclusively created for myself. The real reason why this exist is, I really hate writing HTML within PHP code (especially in classes). If it is more than one line and it is not a template, it looks really ugly and it doesn't feel like it belongs to the code although it does. This package provides a fluent interface for the sole reason of not writing raw HTML in PHP. It also indents and validates the generated HTML and provides IDE-IntelliSense for all HTML elements to make it as easy as it gets.

Examples

Here is an example of how it works:

// on the fly
echo MAKS\PhpHtml\HTML::div('This is a div!', ['class' => 'container']);

// the whole deal
echo (new \MAKS\PhpHtml\HTML())
    ->element('h1', 'HTML Forms', ['class' => 'title'])
    ->open('form', ['method' => 'POST'])
        ->comment('SIMPLE FORM')
        ->h2('Example', ['class' => 'subtitle'])
        ->p('This is an example form.')
        ->br()
        ->if(isset($variable))->div('$variable is set')
        ->open('fieldset')
            ->legend('Form 1', ['style' => 'color: #333;'])
            ->label('Message: ', ['class' => 'text'])
            ->input(['type' => 'text', 'required'])
            ->entity('nbsp')
            ->input(['type' => 'submit', 'value' => 'Submit'])
        ->close()
        ->open('ul', ['class' => 'errors'])
            ->do(function () {
                $errors = ['Error 1', 'Error 2', 'Error 3'];

                foreach ($errors as $error) {
                    $this->li($error);
                }
            })
        ->close()
    ->close()
->render();

The generated HTML would look like this:

<!-- on the fly -->
<div class="container">This is a div!</div>

<!-- the whole deal -->
<h1 class="title">HTML Forms</h1>
<form method="POST">
    <!-- SIMPLE FORM -->
    <h2 class="subtitle">Example</h2>
    <p>This is an example form.</p>
    <br />
    <fieldset>
        <legend style="color: #333;">Form 1</legend>
        <label class="text">Message: </label>
        <input type="text" required />
        &nbsp;
        <input type="submit" value="Submit" />
    </fieldset>
    <ul class="errors">
        <li>Error 1</li>
        <li>Error 2</li>
        <li>Error 3</li>
    </ul>
</form>

License

PHP-HTML is an open-source project licensed under the MIT license.
Copyright (c) 2022 Marwan Al-Soltany. All rights reserved.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-16