is_serialized_string

Check whether serialized data is of string type.

Description

is_serialized_string( (string) $data ); 

Parameters (1)

0. $data (string)
Serialized data.

Usage

  1. if ( !function_exists( 'is_serialized_string' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Serialized data. 
  5. $data = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_serialized_string($data); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function is_serialized_string( $data ) { 
  2. // if it isn't a string, it isn't a serialized string. 
  3. if ( ! is_string( $data ) ) { 
  4. return false; 
  5. $data = trim( $data ); 
  6. if ( strlen( $data ) < 4 ) { 
  7. return false; 
  8. } elseif ( ':' !== $data[1] ) { 
  9. return false; 
  10. } elseif ( ';' !== substr( $data, -1 ) ) { 
  11. return false; 
  12. } elseif ( $data[0] !== 's' ) { 
  13. return false; 
  14. } elseif ( '"' !== substr( $data, -2, 1 ) ) { 
  15. return false; 
  16. } else { 
  17. return true;