# BaseEncode

> Provides reusable HTML encoding for content and attribute values.

[API reference](/docs/api/index.md) › [HTML Helper](/docs/extensions/html-helper/reference/index.md) › [Base](/docs/extensions/html-helper/reference/base/index.md) › BaseEncode

| abstract class | `UIAwesome\Html\Helper\Base\BaseEncode` |
| --- | --- |
| Source | [`src/Base/BaseEncode.php`](https://github.com/ui-awesome/html-helper/blob/main/src/Base/BaseEncode.php#L18) |

1 subclass:

- [`UIAwesome\Html\Helper\Encode`](/docs/extensions/html-helper/reference/encode/index.md)

Provides reusable HTML encoding for content and attribute values.

[`htmlspecialchars()`](https://www.php.net/manual/en/function.htmlspecialchars.php) for encoding implementation details.

See also: <https://www.php.net/manual/en/function.htmlspecialchars.php>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`content()`](#method-content) static | Encodes special characters into HTML entities for use as HTML tag content. | `BaseEncode` |
| [`value()`](#method-value) static | Encodes special characters into HTML entities for use as HTML tag quoted attribute values. | `BaseEncode` |

## Method details

### content() <span id="method-content"></span>

```php
public static function content(string|Stringable $content, bool $doubleEncode = true, string $charset = 'UTF-8'): string
```

Encodes special characters into HTML entities for use as HTML tag content.

Encodes `&`, `<`, and `>` using `ENT_HTML5 | ENT_SUBSTITUTE`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content to be encoded for safe HTML output. |
| `$doubleEncode` | `bool` | Whether to encode existing entities (default: `true`). |
| `$charset` | `string` | Character encoding to use (default: `UTF-8`). |

**Returns**

`string`: Encoded HTML content safe for tag placement.

**See also**

- <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>
- <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>

### value() <span id="method-value"></span>

```php
public static function value(float|int|string|Stringable|null $value, bool $doubleEncode = true, string $charset = 'UTF-8'): string
```

Encodes special characters into HTML entities for use as HTML tag quoted attribute values.

Encodes `&`, `<`, `>`, `"`, and `'` using `ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|null` | Attribute value to be encoded for safe HTML output. |
| `$doubleEncode` | `bool` | Whether to encode existing entities (default: `true`). |
| `$charset` | `string` | Character encoding to use (default: `UTF-8`). |

**Returns**

`string`: Encoded HTML attribute value safe for quoted placement.

**See also**

- <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>
- <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>