diff options
author | Eric Barnes <eric@ericlbarnes.com> | 2012-07-29 06:15:40 +0200 |
---|---|---|
committer | Eric Barnes <eric@ericlbarnes.com> | 2012-07-29 06:15:40 +0200 |
commit | acedd2b1a37b22cb04b01038f21876ddfe38b83a (patch) | |
tree | b3b0a1a347abcbe9c2484072f8d859575654a9aa /system/core/Common.php | |
parent | 62ab8b24fc37a25eab9205c46321fa41729e5faf (diff) |
Adding a common stringify_attributes function for dealing with attributes through out various helpers.
Signed-off-by: Eric Barnes <eric@ericlbarnes.com>
Diffstat (limited to 'system/core/Common.php')
-rw-r--r-- | system/core/Common.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/system/core/Common.php b/system/core/Common.php index 06b162264..d4d01f813 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -598,5 +598,54 @@ if ( ! function_exists('html_escape')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Attributes To String + * + * Helper function used to convert an array or object of + * attributes to a string + * + * @param mixed + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + if (is_object($attributes) && count($attributes) > 0) + { + $attributes = (array) $attributes; + } + + if (is_array($attributes)) + { + $atts = ''; + if (count($attributes) === 0) + { + return $atts; + } + foreach ($attributes as $key => $val) + { + if ($js) + { + $atts .= $key.'='.$val.','; + } + else + { + $atts .= ' '.$key.'="'.$val.'"'; + } + } + return rtrim($atts, ','); + } + elseif (is_string($attributes) && strlen($attributes) > 0) + { + return ' '.$attributes; + } + + return $attributes; + } +} + /* End of file Common.php */ /* Location: ./system/core/Common.php */
\ No newline at end of file |