Source of file Attributes.php
Size: 1,101 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/View/Helper/Attributes.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\View\Helper; use Bluz\View\View; /** * Generate HTML attributes * * @author The-Who * * @var View $this * * @param array $attributes * * @return string */ return function (array $attributes = []) { if (empty($attributes)) { return ''; } $result = []; foreach ($attributes as $key => $value) { if (is_null($value)) { // skip empty values // input: [attribute=>null] // output: '' continue; } elseif (is_int($key)) { // allow non-associative keys // input: [checked, disabled] // output: 'checked disabled' $result[] = $value; } else { $result[] = $key . '="' . htmlspecialchars((string)$value, ENT_QUOTES) . '"'; } } return implode(' ', $result); }; |