Html::formatAttribute PHP Method

formatAttribute() static public method

Formats an individual attribute, and returns the string value of the composed attribute.
static public formatAttribute ( $key, $value ) : string
$key The name of the attribute to create
$value The value of the attribute to create.
return string The composed attribute.
    static function formatAttribute($key, $value)
    {
        if (is_array($value)) {
            $value = implode(' ', $value);
        }
        return sprintf('%1$s="%2$s"', $key, Html::cleanInputText($value));
    }

Usage Example

Example #1
0
 /**
  * Returns a space-delimited string with items of the $options array.
  *
  * @since version 0.85
  *
  * @param $options Array of options.
  *
  * @return string Composed attributes.
  **/
 static function parseAttributes($options = array())
 {
     if (!is_string($options)) {
         $attributes = array();
         foreach ($options as $key => $value) {
             $attributes[] = Html::formatAttribute($key, $value);
         }
         $out = implode(' ', $attributes);
     } else {
         $out = $options;
     }
     return $out;
 }
Html