Skip to content

Commit 39a8f37

Browse files
committed
Update README
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.
1 parent 334deef commit 39a8f37

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

README.md

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# html_build_attributes
22

3-
(PHP 5 >= 5.4)
3+
(PHP 5 >= 5.4, PHP 7, PHP 8)
44
`html_build_attributes` — Generate a string of HTML attributes.
55

66
## Description
@@ -13,17 +13,33 @@ Generate a string of HTML attributes from the associative array provided.
1313

1414
## Parameters
1515

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.
2339

2440
## Return Values
2541

26-
Returns a string of HTML attributes.
42+
Returns a string of HTML attributes or a empty string if `attr` is invalid or empty.
2743

2844
## Installation
2945

@@ -35,4 +51,10 @@ $ composer require mcaskill/php-html-build-attributes
3551

3652
### Without Composer
3753

38-
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
56+
into your project path somewhere.
57+
58+
[class.closure]: https://php.net/class.closure
59+
[function.htmlspecialchars]: https://php.net/function.htmlspecialchars
60+
[wp.esc_attr]: https://developer.wordpress.org/reference/functions/esc_attr/

0 commit comments

Comments
 (0)