is_serialized_string() WordPress Function

The is_serialized_string() function in WordPress checks whether a string is a serialized string. This is useful for checking whether a string is a valid serialized string, before unserializing it.

is_serialized_string( string $data ) #

Check whether serialized data is of string type.


Parameters

$data

(string)(Required)Serialized data.


Top ↑

Return

(bool) False if not a serialized string, true if it is.


Top ↑

Source

File: wp-includes/functions.php

function is_serialized_string( $data ) {
	// if it isn't a string, it isn't a serialized string.
	if ( ! is_string( $data ) ) {
		return false;
	}
	$data = trim( $data );
	if ( strlen( $data ) < 4 ) {
		return false;
	} elseif ( ':' !== $data[1] ) {
		return false;
	} elseif ( ';' !== substr( $data, -1 ) ) {
		return false;
	} elseif ( 's' !== $data[0] ) {
		return false;
	} elseif ( '"' !== substr( $data, -2, 1 ) ) {
		return false;
	} else {
		return true;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.5Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More