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: Wed, 06 Jan 2016 21:12:12 +0000 Organization: A noiseless patient Spider Lines: 22 Message-ID: <87fuyaza37.fsf@bsb.me.uk> References: <568d3dcf$0$23748$e4fe514c@news.xs4all.nl> <87r3huzevd.fsf@bsb.me.uk> <568d6f9c$0$23759$e4fe514c@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="23753"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g7PAgxktuLwpNAZG8eqoRblIUh0aQsKk=" Cancel-Lock: sha1:DaPVsQQAdP5apJHNK42XRDRcKl0= sha1:6bGiOv3aXwjaXr0okxF2VMqfc3o= X-BSB-Auth: 1.4bf2d0d1c6695e30c03b.20160106211212GMT.87fuyaza37.fsf@bsb.me.uk Xref: csiph.com comp.lang.php:16118 "R.Wieser" writes: >> It would be a lot simpler if you could switch to using >> serialize and unserialize. Do you need to use print_r >> for some other reason? > > I'm using it to store the array-of-arrays into a file in human-readable > format. I intend to parse this file using another program, posibly alter > some info and write it back. Well the output of serialise is human-readable (just about). It's not ideal, but then parsing print_r output is not ideal either. In fact, it's not even possible in all cases though you may be able to make enough assumptions about what's in the strings to get away with it. But I would seriously consider some other plan. 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. -- Ben.