string to array conversion. Help please.
| From: | Michael Geary | Date: | Fri, 29 Sep 2000 17:29:56 +0000 |
| Subject: | string to array conversion. Help please. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18083@lists.php.net to get a copy of this message | ||
Hi all,
I'm a bit surprised that PHP4 doesn't offer function-based conversion
between strings and arrays. Yes, I'm familiar with the implode() and
explode() functions, but they don't work well on multi-dimensional or
key-based arrays.
It was relatively easy to write a function to coerce an array into a string
(I'll post this if anyone's interested), however, I'm having more trouble
with going from string into array.
The format I'm using for the string is:
"[fruits:[a:orange,b:banana,c:apple],numbers:[0:[a:orange,b:banana,c:apple],
1:2,2:3,3:4,4:5,5:6],holes:[0:first,5:second,6:third]]"
So, I've got brackets [] defining lists, and colons : defining key:value
pairs.
I've diddled around a bit with various approaches, mainly search & replace
techniques, but I fear I'm going to have to crawl through the string one
char at a time and evaluate whether it is a colon or bracket. I don't think
that's going to be a very smooth solution.
I can't believe no one has solved this (or a similar) problem before, so if
you can comment, I'd be very grateful.
Thanks,
michael geary