1. 首页
  2. WordPress 函数手册

is_serialized()

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&#91;1&#93;="" )="" {="" 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&#91;0&#93;;" 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}:&#91;0-9&#93;+:/s",="" $data="" );="" case="" 'b'="" :="" case="" 'i'="" :="" case="" 'd'="" :="" $end="$strict" '$'="" :="" '';="" return="" (bool)="" preg_match(="" "/^{$token}:&#91;0-9.e-&#93;+;$end/",="" $data="" );="" }="" return="" false;="" }="">
更新版本 源码位置 使用 被使用
2.0.5 wp-includes/functions.php:611 5 0

is_serialized() 为WP2原创文章,链接:https://www.wp2.cn/functions/is_serialized/

发表评论

您的电子邮箱地址不会被公开。