includes/helpers.php
/**
	 * Checks if the given value is a serialized string.
	 *
	 * @param mixed $data
	 * @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
	 * @return bool
	 * @see https://core.trac.wordpress.org/browser/tags/5.0.1/src/wp-includes/functions.php#L0
	 */
Checks if the given value is a serialized string.
@param mixed $data
@param bool $strict Optional. Whether to be strict about the end of the string. Default true.
Checks if the given value is a serialized string . @param mixed $data @param bool $strict Optional . Whether to be strict about the end of the string . Default true .
function is_serialized($data, $strict = true) {
		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, '}');
			if (false === $semicolon && false === $brace) return false;
			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;
				}
			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;
	}
function is_serialized ( $ data , $ strict = true ) { 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 , '}' ) ; if ( false === $ semicolon && false === $ brace ) return false ; 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 ; } 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 ; }
Checks if the given value is a serialized string.
Checks if the given value is a serialized string .