0

我有一个来自会话的数据,我想基于正则表达式进行解析。以下是我想要登录的 3 个数据,名字和姓氏。

login = James 
firstName = James.S 
lastName = Steal


Array (
[user] => __PHP_Incomplete_Class Object (
    [__PHP_Incomplete_Class_Name] => DEX_User
    [permissionID:DE_User:private] => 9
    [login:DE_User:private] => James.S
    [email:DE_User:private] => james.s@domain.com
    [firstName:DE_User:private] => James
    [lastName:DE_User:private] => Steal
    [title:DE_User:private] => Warehouse Man
    [manager:DE_User:private] => Manager's Name
    [workPhone:DE_User:private] => +1 (111) 111-1111
    [mobilePhone:DE_User:private] => +1 (222) 222-2222
    [homePhone:DE_User:private] => +1 (333) 333-3333
    [im:DE_User:private] =>
    [timeDelta:DE_User:private] => Asia/Hongkong
    [lastLogin:DE_User:private] => __PHP_Incomplete_Class Object ( 
        [__PHP_Incomplete_Class_Name] => GB_Date
        [valueStored:protected] => 13545544126666309821
        [mode:protected] => BASE
        [master:protected] =>
    )
    [description:DE_User:private] => Warehouse Engineer
    [isActive:DE_User:private] => __PHP_Incomplete_Class Object (
        [__PHP_Incomplete_Class_Name] => GB_Boolean
        [valueStored:protected] => 1
        [mode:protected] => BASE
        [master:protected] =>
    )
    [isTerminate:DE_User:private] => __PHP_Incomplete_Class Object (
        [__PHP_Incomplete_Class_Name] => GB_Boolean
        [valueStored:protected] =>
        [mode:protected] => BASE
        [master:protected] =>
    )
    [id:protected] => 231968
    [isModifyed:protected] => 
    [needInsert:protected] => 
    [isDeleted] => 
    [isRemoved] => 
)
[enter_password] => 2asas(qwqw)

我试图执行正则表达式'/\[[\/]?[A-Za-z0-9]+\]/';,但我只能在括号内得到它。

谢谢你。

4

1 回答 1

4

您可以评估它,而不是使用 RegExp 解析它。

看看var_export($_SESSION['user']);。这将返回一个可解析的字符串,您将看到的唯一问题是:

__PHP_Incomplete_Class::__set_state

"__PHP_Incomplete_Class" 表示,Session 启动时类未知,仍然无法解析字符串。

但是您可以获取由返回的字符串var_export($_SESSION['user'],true),替换出现的__PHP_Incomplete_Class::__set_statewitharray并且可以评估该字符串:

eval('$user='.str_replace('__PHP_Incomplete_Class::__set_state',
                          'array',
                          var_export($_SESSION['user'],true)).';');

echo $user[0]['login'].',<br/>'.
     $user[0]['firstName'].',<br/>'.
     $user[0]['lastName'];
于 2012-10-29T05:12:58.173 回答