On Wed, Sep 30, 2009 at 23:07, James Colannino <ja...@colannino.org> wrote: > Hey everyone, I was pretty sure there was an easy built-in solution for > what I want to do, but I've been googling around with no luck. > Basically, I just want to take a string containing the output of > print_r() and convert it back into an array again.
Well, print_r() simply iterates the array and prints it.... so if you just want the array, skip print_r() entirely and use the variable you were passing to it. > That is possible, right? If so, how do I go about it? If not, what's a > quick and easy way to parse a string and turn it into an array (I don't > necessarily need the string to be in the format print_r returns). There's plenty of ways to parse strings into arrays, it just depends on how you want to do it. For one example, if you wanted to split each word into an individual array value, you could do: <?php $sentence = "This is a test."; $words = explode(' ',$sentence); /* Then $words would contain:  => This  => is  => a  => test. */ ?> Then, say you wanted to shuffle the words around, and then convert them back to an array. I don't know why, just say it.... out loud. I'll wait. Nevermind, here's the example anyway: <?php // From $words in the previous example.... shuffle($words); $sentence = implode(' ',$words); ?> The latter example will mix up the words and put them back into a sentence, with a whitespace (' ') as the "glue" between them. -- </Daniel P. Brown> daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php