目录
描述
译文
检查值是否被序列化。
如果$data不是字符串,返回的值将是错误的。序列化的数据都是字符串。
原文
Check value to find if it was serialized.
If $data is not a string, then returned value will always be false. Serialized data is always a string.
用法
<?php is_serialized( $data ) ?>
参数
返回值
注意
- 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.
历史
添加于 版本: 2.0.5
源文件
is_serialized() 函数的代码位于 wp-includes/functions.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Check value to find if it was serialized. * * If $data is not an string, then returned value will always be false. * Serialized data is always a string. * * @since 2.0.5 * * @param string $data Value to check to see if was serialized. * @param bool $strict Optional. Whether to be strict about the end of the string. Default true. * @return bool False if not serialized and true if it was. */ 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;="" }=""> |
is_serialized() 源文件
- 原文:http://codex.wordpress.org/Function_Reference/is_serialized
- 翻译:黄聪@WordPress之魂