summaryrefslogtreecommitdiffstats
path: root/system/core
diff options
context:
space:
mode:
authorEric Barnes <eric@ericlbarnes.com>2012-07-29 19:17:50 +0200
committerEric Barnes <eric@ericlbarnes.com>2012-07-29 19:17:50 +0200
commitb01b4f5507523155a598d4ee03d2709a275e88cf (patch)
treecfe86860d3af5ead77bacda9794a4aad7f8925f1 /system/core
parentd83e727d6deedded5b637e685accb4fac0dc3985 (diff)
parent49d2f304d4bb9c04c41c34f4675813b9d8ac3204 (diff)
Merge pull request #1669 from EllisLab/feature/stringify_attributes
Feature/stringify attributes
Diffstat (limited to 'system/core')
-rw-r--r--system/core/Common.php41
1 files changed, 40 insertions, 1 deletions
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 */