Skip to content

esc_attr

Description

Escapes an ordinary value for a quoted HTML attribute.

Usage

<?php

use function Qubus\Security\Helpers\esc_attr;

function esc_attr(string $string): string;

Parameters

$string (string) (required) Attribute to be escaped.

Return Value

(string) Escaped HTML attribute after the esc_attr filter has been applied.

Example

$label = 'Save "draft" <now>';

echo '<button title="' . esc_attr(string: $label) . '">Save</button>';
// <button title="Save &quot;draft&quot; &lt;now&gt;">Save</button>

Always quote the surrounding attribute. This helper does not validate URL, CSS, JavaScript, or srcdoc attributes.