is_serialized()

is_serialized( string $data, bool $strict = true ) 检查值以…

is_serialized( string $data, bool $strict = true )

检查值以确定它是否已序列化。
Check value to find if it was serialized.

目录锚点:#说明#参数#返回#源码


说明(Description)

如果$data不是字符串,则返回值将始终为false。序列化数据始终是字符串。


参数(Parameters)

参数 类型 必填 说明
$data (string) 必需 要检查是否已序列化的值。
$strict (bool) 可选 是否对字符串的结尾严格要求。

返回(Return)

(bool)如果未序列化则为False,如果为true。


源码(Source)

/**
 * Check value to find if it was serialized.
 *
 * If $data is not an string, then returned value will always be false.
 * Serialized data is always a string.
 *
 * @since 2.0.5
 *
 * @param string $data   Value to check to see if was serialized.
 * @param bool   $strict Optional. Whether to be strict about the end of the string. Default true.
 * @return bool False if not serialized and true if it was.
 */
function is_serialized( $data, $strict = true ) {
	// if it isn't a string, it isn't serialized.
	if ( ! is_string( $data ) ) {
		return false;
	}
	$data = trim( $data );
 	if ( 'N;' == $data ) {
		return true;
	}
	if ( strlen( $data ) < 4="" )="" {="" return="" false;="" }="" if="" (="" ':'="" !="=" $data[1]="" )="" {="" return="" false;="" }="" if="" (="" $strict="" )="" {="" $lastc="substr(" $data,="" -1="" );="" if="" (="" ';'="" !="=" $lastc="" &&="" '}'="" !="=" $lastc="" )="" {="" return="" false;="" }="" }="" else="" {="" $semicolon="strpos(" $data,="" ';'="" );="" $brace="strpos(" $data,="" '}'="" );="" either="" ;="" or="" }="" must="" exist.="" if="" (="" false="==" $semicolon="" &&="" false="==" $brace="" )="" return="" false;="" but="" neither="" must="" be="" in="" the="" first="" x="" characters.="" if="" (="" false="" !="=" $semicolon="" &&="" $semicolon="">< 3="" )="" return="" false;="" if="" (="" false="" !="=" $brace="" &&="" $brace="">< 4="" )="" return="" false;="" }="" $token="$data[0];" switch="" (="" $token="" )="" {="" case="" 's'="" :="" if="" (="" $strict="" )="" {="" if="" (="" '"'="" !="=" substr(="" $data,="" -2,="" 1="" )="" )="" {="" return="" false;="" }="" }="" elseif="" (="" false="==" strpos(="" $data,="" '"'="" )="" )="" {="" return="" false;="" }="" or="" else="" fall="" through="" case="" 'a'="" :="" case="" 'o'="" :="" return="" (bool)="" preg_match(="" "/^{$token}:[0-9]+:/s",="" $data="" );="" case="" 'b'="" :="" case="" 'i'="" :="" case="" 'd'="" :="" $end="$strict" '$'="" :="" '';="" return="" (bool)="" preg_match(="" "/^{$token}:[0-9.e-]+;$end/",="" $data="" );="" }="" return="" false;="" }="">
更新版本 源码位置 使用 被使用
2.0.5 wp-includes/functions.php:611 5 0
类别:WordPress 函数手册

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT

登录 账号发表你的看法,还没有账号?立即免费 注册