wp_specialchars()将若干特定字符转换成HTML实体字符

目录

描述

译文

将若干特定字符转换成HTML实体字符。

这与htmlspecialchars有所不同,因为已有HTML实体字符不会被编码。特别注意要将 &转换为 &, < 转换为< 以及 > 转换为 >。

对' to '进行编码时,可以将$quotes设为'single';对" to " 进行编码时则设为'double';对两者同时编码时,则设为'1'。默认值为0,不对引号进行编码。

原文

This function is deprecated as of WordPress 2.8.0. Please use esc_html instead.

Converts a number of special characters into their HTML entities.

Differs from htmlspecialchars as existing HTML entities will not be encoded. Specifically changes: & to &#038;, < to &lt; and > to &gt;.

$quotes can be set to 'single' to encode ' to &#039;, 'double' to encode " to &quot;, or '1' to do both. Default is 0 where no quotes are encoded.

wp_specialchars() 描述

用法

<?php wp_specialchars$text$quotes ?>

wp_specialchars() 用法

参数

$text

(string) (必填) The text which is to be encoded.

默认值: None

$quotes

(mixed) (可选) Converts single quotes if set to 'single', double if set to 'double' or both if otherwise set.

默认值: 0

wp_specialchars() 参数

返回值

(string) 

The encoded text with HTML entities.

wp_specialchars() 返回值

注意

wp_specialchars() 注意

历史

添加于 版本: 1.2.2

wp_specialchars() 历史

源文件

wp_specialchars() 函数的代码位于 wp-includes/formatting.php.

wp_specialchars() 源文件