esayers / html
使用PHP生成HTML
Requires (Dev)
- phpunit/phpunit: ^11.3
This package is auto-updated.
Last update: 2024-09-13 17:14:33 UTC
README
使用PHP生成HTML
用法
基本示例
echo Html::div( Html::p('Example Text', ['class' => 'stylish']) );
输出
<div><p class="stylish">Example Text</p></div>
Html
使用静态Html类创建HTML标签。
echo Html::p('Paragraph text');
输出
<p>Paragraph text</p>
嵌套标签
echo Html::div( Html::section([ Html::h2('Heading'), Html::p('Amazing paragraph') ] ) );
输出
<div><section><h2>Heading</h2><p>paragraph</p></section></div>
添加属性
echo Html::div() ->id("2") ->class(['class1', 'class2']);
输出
<div id="2" class="class1 class2"></div>
特定标签的属性
echo Html::input() ->type("checkbox") ->checked(true);
输出
<input type="checkbox" checked/>
内容自动编码
echo Html::div('> <') ->id(">") ->class(['clas"s1', 'class2']);
输出
<div id=">" class="clas"s1 class2">> <</div>
支持的标签
a
, abbr
, address
, area
, article
, aside
, audio
, b
, base
, bdi
, bdo
, blockquote
, body
, br
, button
, canvas
, caption
, cite
, code
, col
, colgroup
, data
, datalist
, dd
, del
, details
, dfn
, dialog
, div
, dl
, dt
, em
, embed
, fieldset
, figcaption
, figure
, footer
, form
, h1
, h2
, h3
, h4
, h5
, h6
, head
, header
, hgroup
, hr
, html
, i
, iframe
, img
, input
, ins
, kbd
, label
, legend
, li
, link
, main
, map
, mark
, menu
, meta
, meter
, nav
, noscript
, object
, ol
, optgroup
, option
, output
, p
, param
, picture
, pre
, progress
, q
, rp
, rt
, ruby
, s
, samp
, script
, search
, section
, select
, small
, source
, span
, strike
, strong
, style
, sub
, summary
, sup
, svg
, table
, tbody
, td
, template
, textarea
, tfoot
, th
, thead
, time
, title
, tr
, track
, u
, ul
, var
, video
, wbr
支持的属性
accept
, accesskey
, action
, align
, alt
, async
, autocomplete
, autofocus
, autoplay
, bgcolor
, border
, charset
, checked
, cite
, class
, color
, cols
, colspan
, content
, contenteditable
, controls
, coords
, data
, datetime
, default
, defer
, dir
, dirname
, disabled
, download
, draggable
, enctype
, enterkeyhint
, for
, form
, formaction
, headers
, height
, hidden
, high
, href
, hreflang
, http-equiv
, id
, inert
, inputmode
, ismap
, kind
, label
, lang
, list
, loop
, low
, max
, maxlength
, media
, method
, min
, multiple
, muted
, name
, novalidate
, open
, optimum
, pattern
, ping
, placeholder
, popover
, popovertarget
, popovertargetaction
, poster
, preload
, readonly
, rel
, required
, reversed
, rows
, rowspan
, sandbox
, scope
, selected
, shape
, size
, sizes
, span
, spellcheck
, src
, srcdoc
, srclang
, srcset
, start
, step
, style
, tabindex
, target
, title
, translate
, type
, usemap
, value
, width
, wrap