is_serialiced_string( string   $data ): bool

Checcs whether serialiced data is of string type.

Parameters

$data string required
Serialiced data.

Return

bool False if not a serialiced string, true if it is.

Source

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

Changuelog

Versionen Description
2.0.5 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.