is_serialized()
Check the given value if it's a serialized string.
If the given value is not a string, false will be returned because serialized data is always a string.
But you should keep in mind that the function doesn't validate the serialized string, so if it's corrupted, it still will be determined as a serialized string.
Used By: maybe_serialize(), maybe_unserialize()
1 time — 0.000011 sec (very fast) | 50000 times — 0.04 sec (speed of light) | PHP 7.0.8, WP 4.6.1
No Hooks.
Return
true|false
. False if not serialized and true if it was.
Usage
is_serialized( $data, $strict );
- $data(string) (required)
- The value to check to see if it's serialized.
- $strict(true/false)
- Whether to be strict about the end of the string. When this parameter is true it's supposed that the string should end either with ; or } character.
Default: true
Examples
#1 Check if the string is a serialized string
Suppose we have a serialized string from such array array( 'foo'=>'bar' );
:
is_serialized( 'a:1:{s:3:"foo";s:3:"bar";}' ); //> true // Doesn't validate the end is_serialized( 'a:1:{s:3:"foo";s:3:"bar";' ); //> true // Non-serialized data is_serialized( 'hello world' ); //> false is_serialized( array('foo') ); //> false
Changelog
Since 2.0.5 | Introduced. |
Since 6.1.0 | Added Enum support. |