Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.php Subject: Re: parsing print_r() output with preg_match_all() Date: Thu, 07 Jan 2016 11:18:07 +0000 Organization: A noiseless patient Spider Lines: 32 Message-ID: <87egdty6xc.fsf@bsb.me.uk> References: <568d3dcf$0$23748$e4fe514c@news.xs4all.nl> <87r3huzevd.fsf@bsb.me.uk> <568d6f9c$0$23759$e4fe514c@news.xs4all.nl> <87fuyaza37.fsf@bsb.me.uk> <568e2b23$0$23766$e4fe514c@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="14948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NWpbhBo1lMS2AeLlUqviz3IB2t8H8L6w=" Cancel-Lock: sha1:R55TTZ662AItpAsvMcHbuUkK1QE= sha1:cdXsM/u7yoRIrkzkmc6W/xxY8uU= X-BSB-Auth: 1.9f46c5f1743aa53fa82e.20160107111807GMT.87egdty6xc.fsf@bsb.me.uk Xref: csiph.com comp.lang.php:16133 "R.Wieser" writes: > Ben, > >> Well the output of serialise is human-readable (just about). > > It cannot hurt to take a look at how it works and looks. > >> If it's always going to be just an array of arrays of strings, >> you could design your own human-readable format whilst >> making it (much) easier to read back. > > Thats very possible. Currently I'm trying some code to just parse the > print_r() output, starting with exploding the data into its lines. > I just tought it would be a good idea to try to use/adapt something which > already worked. > > And you're right, I only storing simple (one-line) strings. If you put each string on a line and separate the arrays with a blank line you can read it back using array_map(function ($s) { return explode("\n", $s); }, explode("\n\n", get_file_contents($filename))); though you may need to do some white space trimming, and if you can't assume anonymous functions, it's hardly much longer. Of course, you then can't extend the format and you might need to document it... -- Ben.