wp_kses_check_attr_val()执行属性值的差异性检查

目录

描述

译文

该函数为属性值执行不同查询。

目前可执行的查询包括'maxlen', 'minlen', 'maxval', 'minval' 以及 'valueless',将来可能会支持更多可执行查询。

原文

Performs different checks for attribute values.

The currently implemented checks are 'maxlen', 'minlen', 'maxval', 'minval' and 'valueless' with even more checks to come soon.

wp_kses_check_attr_val() 描述

用法

<?php wp_kses_check_attr_val$value$vless$checkname$checkvalue ?>

wp_kses_check_attr_val() 用法

参数

$value

(string) (必填) Attribute value

默认值: None

$vless

(string) (必填) Whether the value is valueless or not. Use 'y' or 'n'

默认值: None

$checkname

(string) (必填) What $checkvalue is checking for.

默认值: None

$checkvalue

(mixed) (必填) What constraint the value should pass

默认值: None

wp_kses_check_attr_val() 参数

返回值

(boolean) 

Whether check passes (true) or not (false)

wp_kses_check_attr_val() 返回值

历史

添加于 版本: 1.0.0

wp_kses_check_attr_val() 历史

源文件

wp_kses_check_attr_val() 函数的代码位于 wp-includes/kses.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Performs different checks for attribute values.
 *
 * The currently implemented checks are "maxlen", "minlen", "maxval", "minval"
 * and "valueless".
 *
 * @since 1.0.0
 *
 * @param string $value      Attribute value
 * @param string $vless      Whether the value is valueless. Use 'y' or 'n'
 * @param string $checkname  What $checkvalue is checking for.
 * @param mixed  $checkvalue What constraint the value should pass
 * @return bool Whether check passes
 */
function wp_kses_check_attr_val($value, $vless, $checkname, $checkvalue) {
	$ok = true;

	switch (strtolower($checkname)) {
		case 'maxlen' :
			// The maxlen check makes sure that the attribute value has a length not
			// greater than the given value. This can be used to avoid Buffer Overflows
			// in WWW clients and various Internet servers.

			if (strlen($value) > $checkvalue)
				$ok = false;
			break;

		case 'minlen' :
			// The minlen check makes sure that the attribute value has a length not
			// smaller than the given value.

			if (strlen($value) < $checkvalue)="" $ok="false;" break;="" case="" 'maxval'="" :="" the="" maxval="" check="" does="" two="" things:="" it="" checks="" that="" the="" attribute="" value="" is="" an="" integer="" from="" 0="" and="" up,="" without="" an="" excessive="" amount="" of="" zeroes="" or="" whitespace="" (to="" avoid="" buffer="" overflows).="" it="" also="" checks="" that="" the="" attribute="" value="" is="" not="" greater="" than="" the="" given="" value.="" this="" check="" can="" be="" used="" to="" avoid="" denial="" of="" service="" attacks.="" if="" (!preg_match('/^s{0,6}[0-9]{1,6}s{0,6}$/',="" $value))="" $ok="false;" if="" ($value=""> $checkvalue)
				$ok = false;
			break;

		case 'minval' :
			// The minval check makes sure that the attribute value is a positive integer,
			// and that it is not smaller than the given value.

			if (!preg_match('/^s{0,6}[0-9]{1,6}s{0,6}$/', $value))
				$ok = false;
			if ($value < $checkvalue)="" $ok="false;" break;="" case="" 'valueless'="" :="" the="" valueless="" check="" makes="" sure="" if="" the="" attribute="" has="" a="" value="" (like="">) or not (

wp_kses_check_attr_val() 源文件