Class dom
Document Object Model utilities
To get started, place the following line around top of your code.
use amekusa\plz\dom;
Methods summary
public static
string
|
#
attr( string $Name, mixed $Value, mixed $Default = null )
Returns a DOM attribute expression
Returns a DOM attribute expression
Parameters
- $Name
- Attribute name
- $Value
- Attribute value
- $Default
- (optional) Default value of the attribute
Returns
string DOM attribute expression
Example
"class" attribute
$class = 'cols';
echo '<div' . dom::attr('class', $class) . '>';
<div class="cols">
Returns nothing if the value is empty
$class = '';
echo '<div' . dom::attr('class', $class) . '>';
<div>
Boolean attribute
echo '<input type="radio"' . dom::attr('checked', true) . '/>' . "\n";
echo '<input type="radio"' . dom::attr('checked', false) . '/>';
<input type="radio" checked="checked"/>
<input type="radio"/>
|
public static
string
|
#
attrs( array|object $Attrs )
Returns DOM attribute(s) expression
Returns DOM attribute(s) expression
Parameters
- $Attrs
- Associative array the structure of which is
[Name => Value]
Returns
string DOM attribute(s) expression
Example
Multiple attributes
$var = array (
'name' => 'eula',
'type' => 'checkbox',
'value' => 'agreed'
);
echo '<input' . dom::attrs($var) . '/>';
<input name="eula" type="checkbox" value="agreed"/>
|