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

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

WBOY
Release: 2016-07-12 09:02:47
Original
780 people have browsed it

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

esc_attr() (filter attribute)
Generally when writing the tag attributes 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.

How to use

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 statements)
esc_sql() is used to filter the strings to be added to Sql statements to prevent Sql injection and Sql statements from being interfered with by data and causing exceptions.

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


Articles you may be interested in:

  • WordPress code to determine whether the user is logged in
  • Detailed explanation of the function of reminding to install plug-ins and hiding plug-ins in WordPress
  • Sharing code examples for adding prompt boxes to the WordPress editing backend
  • Analysis of relevant PHP functions for writing custom storage fields in WordPress
  • Detailed explanation of the use of relevant PHP functions for creating user roles in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084527.htmlTechArticleDetailed explanation of the function use of filter attributes and Sql statements in WordPress development, esc_attr() (filter attribute) is generally written in Html The tag attribute of the code will be in the following format: input ty...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template