Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Is Serialized 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 ( false === strpos( $data, '"' ) ) {
                return false;
            }
            // Or else fall through.
        case 'a':
        case 'O':
            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;
}
Comment

PREVIOUS NEXT
Code Example
Php :: woocommerce hook after order placed 
Php :: laravel get age from date 
Php :: throwable php 
Php :: show woocommerce product variation in table php 
Php :: laravel get id from insert 
Php :: convert array into , separated string in php 
Php :: wordpress reserved image size names 
Php :: wp php go back 
Php :: how to download image from url from a particular div in php 
Php :: how to show image in laravel 
Php :: laravel collective form include image 
Php :: laravel casts 
Php :: mail sending setting magneto for mailhog 
Php :: nl2br() php 
Php :: generate entities symfony 
Php :: axios post not sending data php 
Php :: php reverse dns lookup 
Php :: laravel request get parameter 
Php :: how to check if all values in an array are equal php 
Php :: img upload in php 
Php :: eloquent where comparing two columns 
Php :: insertion sort in php 
Php :: insert batch in laravel 
Php :: how to give optional parameter in route 
Php :: run codeigniter 4 with spark 
Php :: php array_push in foreach duplicate 
Php :: php number format without rounding 
Php :: minishlink/web-push v5.2.5 requires ext-gmp * 
Php :: pdo connection 
Php :: elementor woo product hide add to cart 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =