Describes how to filter attributes and use SQL statements in WordPress development. _ PHP Tutorial

Source: Internet
Author: User
Describes how to filter attributes and use SQL statements in WordPress development ,. The following section describes how to use the filter attributes and SQL statement functions in WordPress development. esc_attr () (filter attributes) generally uses the following format when writing the tag attributes of Html code: inputty describes how to filter attributes and use SQL statements in WordPress development,

Esc_attr () (filter attribute)
Generally, the tag attribute of Html code is written in the following format:

 

What if the value attribute is dynamically output?

 

However, if the dynamic output attribute contains special characters such as double quotation marks and angle brackets, the Html code will be disrupted. in this case, you can use the esc_attr () function to escape the output attribute.

Usage

esc_attr( $text );

Parameters

$ Text (string) (required) the string to be escaped. Default value: None

Return value

Returns the escaped string.

Example

 

Others

This function is located in: 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 exceptions caused by data interference.

Usage

esc_sql( $data );

Parameters

$ Data

(String) (required) the string to be filtered.

Default value: None

Return value

(String) the filtered string can be directly added 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'" );

More

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


Articles you may be interested in:
  • Code used by WordPress to determine whether a user is logged on
  • Install the plug-in and hide the functions of the plug-in WordPress.
  • Add code instances in the prompt box to the WordPress editing background
  • PHP function parsing for writing custom storage fields in WordPress
  • PHP functions used to create user roles in WordPress

Encoding, esc_attr () (filter attribute) generally, when writing the tag attribute of Html code, it will be in the following format: input ty...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.