How to create an array from output of var_dump in PHP?

前端 未结 6 1953
谎友^
谎友^ 2021-01-13 06:53

How can I parse the output of var_dump in PHP to create an array?

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 07:53

    I had a similar problem : a long runing script produced at the end a vardump of large array. I had to parse it back somehow for further analyzis. My solution was like this:

    cat log.stats  | 
      sed 's/\[//g' | 
      sed 's/\]//g' | 
      sed -r 's/int\(([0-9]+)\)/\1,/g' | 
      sed 's/\}/\),/g' | 
      sed -r 's/array\([0-9]+\) \{/array(/g' > 
      log.stats.php
    

提交回复
热议问题