WordPress at Your Fingertips

is_serialized_string() WP 1.0

Check whether serialized data is of string type.

1 time — 0.000039 sec (very fast) | 50000 times — 0.03 sec (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.

Changelog

Since 2.0.5 Introduced.

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

From tag: serialize

No comments
    Log In