WordPress.org

Ready to get started?Download WordPress

Codex

zh-cn:函数/esc attr

Contents

Description

Encodes < > & " ' (less than, greater than, ampersand, double quote, single quote). Will never double encode entities.

Always use when escaping user-input, in forms especially.

对于字符串进行转义字符处理。

Usage

<?php echo esc_attr$text ?>

Parameters

$text
(string) (required) The text which is to be encoded.
Default: None

Return Values

(string) 
The encoded text with HTML entities.

Examples


<?php
echo '<input type=\"text\" id=\"user-email\" name=\"user-email\" value=\"' esc_attr$_POST['email'] ) . '\">';  
?>

Change Log

Since: 2.8.0

Source File

esc_attr() is located in wp-includes/formatting.php.

Related

See: Data Validation article for an in-depth discussion of input and output sanitization.

See also index of Function Reference and index of Template Tags.