From a1abadaab34d8d08c54557c7e60d12eb624b72fe Mon Sep 17 00:00:00 2001 From: Chad Furman Date: Sun, 29 Jul 2012 01:03:50 -0400 Subject: refactored (crunched down) _stringify_attributes --- system/core/Common.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'system/core/Common.php') diff --git a/system/core/Common.php b/system/core/Common.php index 06b162264..5cd3961d1 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -598,5 +598,44 @@ if ( ! function_exists('html_escape')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Stringify attributes for use in html tags. + * + * Helper function used to convert a string, array, or object of + * attributes to a string + * + * @param mixed string, array, object + * @param bool + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + $atts = null; + + if (empty($attributes)) + { + return $atts; + } + + if (is_string($attributes)) + { + return ' '.$attributes; + } + + $attributes = (array) $attributes; + + foreach ($attributes as $key => $val) + { + $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; + } + + return rtrim($atts, ','); + } +} + /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b