How can I parse the output of var_dump
in PHP to create an array?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Maybe you’re looking for
var_export
that will give you a valid PHP expression of the passed value.You can't.
var_dump
just outputs text but doesn't return anything.Perhaps you are trying to convert an object to an array? http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html
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:
Use var_export if you want a representation which is also valid PHP code
will display
To turn that back into an array, you can use eval, e.g.
Not sure why you would want to do this though. If you want to store a PHP data structure somewhere and then recreate it later, check out serialize() and unserialize() which are more suited to this task.
var_export
creates the PHP code, which you can run through theeval
.But I wonder, what is your idea?