The output of print_r()
is not designed to parsed; it's designed to be read by a developer for debugging purposes. You should not be trying to parse it.
If you really must parse a PHP data dump of this nature, the var_export() function is intended for this kind of thing. However, I wouldn't recommend parsing this either -- it's still unlikely to be the best solution for you.
If your intention is to store a string representation of an array structure, and then parse it later, you would be better off using either the serialize()
/unserialize()
functions, or the json_encode()
/json_decode()
functions.
Both of these will give you a much more reliable and easily parseable data dump format. Of the two, I'd recommend json_encode()
every time, as not only is it easy to work with, it's also supported by other languages, easy to read manually, and compact.
In short, don't parse print_r()
output; use json_encode()
/json_decode()
instead.
http://uk1.php.net/manual/en/function.json-encode.php