WordPress at a glance

is_serialized_string() WP 1.0

Check whether serialized data is of string type.

✈ 1 time = 0.000039s = very fast | 50000 times = 0.03s = speed of light PHP 7.0.8, WP 4.6.1

No Hooks.

Return

true/false. False if not a serialized string, true if it is.

Usage

is_serialized_string( $data );
$data(string) (required)
Serialized data.

Code of is_serialized_string: wp-includes/functions.php VER 4.9.8

<?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 ( $data[0] !== 's' ) {
		return false;
	} elseif ( '"' !== substr( $data, -2, 1 ) ) {
		return false;
	} else {
		return true;
	}
}

Related Functions

From tag: serialize

More from category: Helper Functions

No comments
    Hello, !     Log In . Register