Home > Backend Development > PHP Tutorial > Detailed explanation of the use of filter attributes and functions of Sql statements in WordPress development

Detailed explanation of the use of filter attributes and functions of Sql statements in WordPress development

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:09:10
Original
943 people have browsed it

esc_attr() (filter attribute)
Generally when writing the tag attribute of Html code, it will be in the following format:

<input type="text" name="rep" value="rep_value" />
Copy after login

What if the value attribute is output dynamically?

<input type="text" name="rep" value="<&#63;php echo get_option( 'rep_value' ); &#63;>" />
Copy after login

However, if the dynamically output attributes contain special characters such as double quotes and angle brackets, the Html code will be disrupted. In this case, you can use the esc_attr() function to escape the output attributes.

Usage

esc_attr( $text );
Copy after login

Parameters

$text (String) (required) The string to be escaped. Default value: None

Return value

Returns the escaped string.

Example

<input type="text" name="rep" value="<&#63;php echo esc_attr( get_option( 'rep_value' ) ); &#63;>" />
Copy after login

Others

This function is located at: wp-includes/formatting.php

esc_sql() (filter Sql statement)
esc_sql() is used to filter the strings to be added to the Sql statement to prevent Exceptions occur when Sql injection and Sql statements are interfered with by data.

Usage

esc_sql( $data );
Copy after login

Parameters

$data

(String) (required) The string to filter.

Default value: None

Return value

(String) Returns the filtered string, which can be added directly to the Sql statement.

Example

$name = esc_sql( $name );
$status = esc_sql( $status );
$wpdb->get_var( "SELECT something FROM table WHERE foo = '$name' and status = '$status'" );

Copy after login

More

This function is located at: wp-includes/formatting.php

The above has introduced a detailed explanation of the use of filter attributes and Sql statement functions in WordPress development, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template