0

I have multidimensional and quite complex array that holds different data types, booleans, text inputs, and even whole textareas with all white space, html tags and so forth.

What's the best PHP way of displaying my array as a string of compressed data so I'd be able to export and store (let's say in .txt file) it? I'm going to need to restore this data in the future (import the data through text input field) , so it must be parsable. I'd love this string to be as short as possible. Any hints?

Wordpressor
  • 7,173
  • 23
  • 69
  • 108
  • 1
    If you want it to be parseable, you can use var_export — Outputs or returns a parsable string representation of a variable. For more details refer http://stackoverflow.com/a/3975916/1221837 answer. – Anup Khandelwal Oct 29 '13 at 16:26

2 Answers2

7

Did you have a look at serialize? http://php.net/manual/en/function.serialize.php

Additionally, if you want to shorten the result, you may want to compress it. See the gzip family.

aspyct
  • 3,625
  • 7
  • 36
  • 61
1

I don't know what kind of output you need.

Maybe var_export or json_encode can be useful for you

$v = var_export($b, true);
echo $v;
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97