Title: is_serialized
Published: April 25, 2014
Last modified: February 24, 2026

---

# is_serialized( string $data, bool $strict = true ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#wp--skip-link--target)

Checks value to find if it was serialized.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#description)󠁿

If $data is not a string, then returned value will always be false.
Serialized data
is always a string.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#parameters)󠁿

 `$data`stringrequired

Value to check to see if was serialized.

`$strict`booloptional

Whether to be strict about the end of the string.

Default:`true`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#return)󠁿

 bool False if not serialized and true if it was.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#more-information)󠁿

##### 󠀁[Usage:](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#usage)󠁿

    ```php
    is_serialized( $data );
    ```

##### 󠀁[Notes:](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#notes)󠁿

Data might need to be _serialized_ to allow it to be successfully stored and retrieved
from a database in a form that PHP can understand.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#source)󠁿

    ```php
    function is_serialized( $data, $strict = true ) {
    	// If it isn't a string, it isn't serialized.
    	if ( ! is_string( $data ) ) {
    		return false;
    	}
    	$data = trim( $data );
    	if ( 'N;' === $data ) {
    		return true;
    	}
    	if ( strlen( $data ) < 4 ) {
    		return false;
    	}
    	if ( ':' !== $data[1] ) {
    		return false;
    	}
    	if ( $strict ) {
    		$lastc = substr( $data, -1 );
    		if ( ';' !== $lastc && '}' !== $lastc ) {
    			return false;
    		}
    	} else {
    		$semicolon = strpos( $data, ';' );
    		$brace     = strpos( $data, '}' );
    		// Either ; or } must exist.
    		if ( false === $semicolon && false === $brace ) {
    			return false;
    		}
    		// But neither must be in the first X characters.
    		if ( false !== $semicolon && $semicolon < 3 ) {
    			return false;
    		}
    		if ( false !== $brace && $brace < 4 ) {
    			return false;
    		}
    	}
    	$token = $data[0];
    	switch ( $token ) {
    		case 's':
    			if ( $strict ) {
    				if ( '"' !== substr( $data, -2, 1 ) ) {
    					return false;
    				}
    			} elseif ( ! str_contains( $data, '"' ) ) {
    				return false;
    			}
    			// Or else fall through.
    		case 'a':
    		case 'O':
    		case 'E':
    			return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
    		case 'b':
    		case 'i':
    		case 'd':
    			$end = $strict ? '$' : '';
    			return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data );
    	}
    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L674)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L674-L731)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_targeted_link_rel()](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/)`wp-includes/formatting.php` |

Adds `rel="noopener"` to all HTML A elements that have a target.

  | 
| [WP_Customize_Manager::import_theme_starter_content()](https://developer.wordpress.org/reference/classes/wp_customize_manager/import_theme_starter_content/)`wp-includes/class-wp-customize-manager.php` |

Imports theme starter content into the customized state.

  | 
| [_list_meta_row()](https://developer.wordpress.org/reference/functions/_list_meta_row/)`wp-admin/includes/template.php` |

Outputs a single row of public meta data in the Custom Fields meta box.

  | 
| [maybe_serialize()](https://developer.wordpress.org/reference/functions/maybe_serialize/)`wp-includes/functions.php` |

Serializes data, if needed.

  | 
| [maybe_unserialize()](https://developer.wordpress.org/reference/functions/maybe_unserialize/)`wp-includes/functions.php` |

Unserializes data only if it was serialized.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added Enum support. | 
| [2.0.5](https://developer.wordpress.org/reference/since/2.0.5/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/is_serialized/?output_format=md#comment-content-6677)
 2.   [Arunlal Panja](https://profiles.wordpress.org/arunlalpanja/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/is_serialized/#comment-6677)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_serialized%2F%23comment-6677)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_serialized%2F%23comment-6677)
 4. If it is not serialized, then serialize array into a string format.
 5.     ```php
        $data = array( 'John Doe', 'johndoe@example.com', 1234567890 );
        if ( ! is_serialized( $data ) ) {
            $data = maybe_serialize( $data );
        }
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_serialized%2F%3Freplytocom%3D6677%23feedback-editor-6677)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_serialized%2F)
before being able to contribute a note or feedback.