Ric*_*nop 5 php regex serialization
我在我的应用程序中有这个功能:
public function direct($theTree)
{
$aTreeRoot = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $theTree);
return unserialize($aTreeRoot);
}
Run Code Online (Sandbox Code Playgroud)
它应该永远不会返回false,但在错误日志中会出现错误,表示返回false.
但是,我无法在我的应用程序中复制错误.我正在尝试一切可能的方式,但它始终有效.
这个功能有问题吗?
将$theTree来自会话.
编辑:正则表达式是因为:unserialize- 在评论中搜索我的正则表达式.它应该解决一个问题.
Poo*_*att 40
我之前遇到过类似的问题.我告诉你我是如何解决它的.
序列化数据后,应用base64_encode()例如
$txt = base64_encode(serialize($txt));
Run Code Online (Sandbox Code Playgroud)
当你反序列化它
例如
$txt = unserialize(base64_decode($txt));
Run Code Online (Sandbox Code Playgroud)
试试这个 .希望也为你工作.祝好运