LaravelBook\Laravel4Powerpack\HTML::attributes PHP Method

attributes() public method

Build a list of HTML attributes from an array
public attributes ( array $attributes ) : string
$attributes array
return string
    public function attributes($attributes)
    {
        $html = array();
        foreach ((array) $attributes as $key => $value) {
            // For numeric keys, we will assume that the key and the value are the
            // same, as this will convert HTML attributes such as "required" that
            // may be specified as required="required", etc.
            if (is_numeric($key)) {
                $key = $value;
            }
            if (!is_null($value)) {
                $html[] = $key . '="' . $this->entities($value) . '"';
            }
        }
        return count($html) > 0 ? ' ' . implode(' ', $html) : '';
    }

Usage Example

Example #1
0
 /**
  * Create a HTML button element.
  *
  * @param string  $value
  * @param array   $attributes
  * @return string
  */
 public function button($value = null, $attributes = array())
 {
     return '<button' . $this->html->attributes($attributes) . '>' . $this->html->entities($value) . '</button>';
 }