You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changed:
- Hard-wrapped lines to ~80 characters for consistent reading.
- Updated version information to indicate function is compatible with PHP 7 and PHP 8.
- Improved description of parameters and return values.
- Replaced inline links with reference links.
`html_build_attributes` — Generate a string of HTML attributes.
5
5
6
6
## Description
@@ -13,17 +13,33 @@ Generate a string of HTML attributes from the associative array provided.
13
13
14
14
## Parameters
15
15
16
-
-`attr` — Associative array, or object containing properties, representing attribute names and values.
17
-
If `attr` is an object, then only public properties will be incorporated into the result.
18
-
If a value is an array, its values will be concatenated and delimited with a space.
19
-
Values that cannot be converted into strings will be ignored. If the value is Stringable, Arrayble, or a `Closure`, attempts will be made to parse as a string.
20
-
-`callback` — Callback function for escaping the values for the HTML attributes.
21
-
If no sanitizer is provided, [`htmlspecialchars()`](http://php.net/htmlspecialchars) is used;
22
-
If using WordPress, the [`esc_attr()`](https://developer.wordpress.org/reference/functions/esc_attr/) function is used.
16
+
-`attr` — Associative array, or object containing properties, representing
17
+
attribute names and values.
18
+
19
+
If `attr` is a non-iterable object, then only accessible non-static properties
20
+
will be incorporated into the result.
21
+
22
+
If a value of `attr` is an array, its values will be concatenated and
23
+
delimited with a space.
24
+
25
+
If a value of `attr` is a boolean, the value's key will be rendered without
26
+
a value.
27
+
28
+
If the value is Stringable, Arrayble, or a [`Closure`][class.closure],
29
+
attempts will be made to parse as a string.
30
+
31
+
Values that cannot be converted into strings will be ignored.
32
+
33
+
-`callback` — Callback function for escaping the values for the HTML attributes.
34
+
35
+
If no sanitizer is provided, [`htmlspecialchars()`][function.htmlspecialchars]
36
+
is used;
37
+
38
+
If using WordPress, the [`esc_attr()`][wp.esc_attr] function is used.
23
39
24
40
## Return Values
25
41
26
-
Returns a string of HTML attributes.
42
+
Returns a string of HTML attributes or a empty string if `attr` is invalid or empty.
Why are you not using [composer](http://getcomposer.org/)? Download `Function.HTML-Build-Attributes.php` from the gist and save the file into your project path somewhere.
54
+
Why are you not using [composer](http://getcomposer.org/)?
55
+
Download `Function.HTML-Build-Attributes.php` from the gist and save the file
0 commit comments