Hi - how do I convert an array string into an array (i.e. the following values into an array). It may already look like an array but PHP is seeing it as a string (just need to convert it please).
Array
(
[plaintext] => This is an example CV.
[filename] => 1345550846.doc
)
Find the contents of the array(s). (Hint: preg_match_all)
Foreach of those contents, explode on line breaks.
Foreach line, explode on =>.
Trim the first component. Left trim the second, right trim the last.
the key is defined as the first element of the components, from index 1 to -1 (hint: substr). The value is defined as the remaining elements imploded on => (in case there is a => in the value).
Okay, is that the var_dump of the expected output or of the data you have that you want to convert? As if that is the data you want to convert, you already have a PHP array, if it is the expected output, can you provide the var_dump of the data you want to convert as well?
From what i read, cp, the input is a multi-line sting, in the format shown in the OP.
Take that STRING. (not an array object, an actual string. As if you’d screen-scraped the output of a print_r. and convert it into it’s array equivilant.
Okay, I’ll try playing around with a few regular expressions when I get home, that could hopefully simplify this process. As if you can write a regex that matches the key and the value of said key, you can then loop through the matches to create your associative array.
Your updated code has quotes around the array keys, I didn’t see that in the original text you posted. In fact, that is entirely different than the original text you posted, so which text do you have to convert?
Just where are you getting this “array string”…and how do you know it is not actually an array? And just maybe, you can help yourself instead of being spoon fed like…[omitted]. Most of the code to convert the “array string” with regex is provided. Now help yourself for a change and make the necessary edits to solve the issue on Post #11.
Yes I know I could be nicer…
But those that don’t help themselves just aggravate me to no end.