dougui1977 2012-10-29 01:27
浏览 30
已采纳

使用regex解析会话数据

I have a data that came from a session and I want to parse base on regex. Below are the 3 data that I want to get login, firstName and lastName.

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)

I tried to perform regexp '/\[[\/]?[A-Za-z0-9]+\]/'; but i can only get that inside the bracket.

Thank you.

  • 写回答

1条回答 默认 最新

  • dongxieyou3314 2012-10-29 05:12
    关注

    Instead of parsing it using RegExp you may evaluate it.

    Take a look at var_export($_SESSION['user']); . This returns a parseable string, the only problem you will see there is :

    __PHP_Incomplete_Class::__set_state
    

    "__PHP_Incomplete_Class" means, the class was unknown when the Session was started, the string still can't be parsed.

    But you can take the string returned by var_export($_SESSION['user'],true) , replace the occurences of __PHP_Incomplete_Class::__set_state with array and the string can be evaluated:

    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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题