Re: Re: Parse string with variables

From: Date: Wed, 31 May 2006 12:15:49 +0000
Subject: Re: Re: Parse string with variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-237143@lists.php.net to get a copy of this message
On 5/31/06, Barry <barry@flyerheaven.de> wrote:
Merlin schrieb: Hi there, I am trying to parse a plain text which contains variables. The string looks like this: P=1 U=test T=ok P=2 U=test2 T=anything How could I create arrays out of this. To be able to access the values like this: echo $P[1]; parse_str does not work here and I could not find another function which does this. Thank you for any hint, Merlin quite less infos you give. echo $P[2] would output test or what? $U["test"] or $U[1] = test ?? a hint. Uhm, use regexpressions to split the string and form variables out of it. my guess. Barry
OR, you could try : 1st split the text by newline into array. Then split every element of the resulting array by '=' and then you have all you need to create the variables, i guess :) simple example : $text_arr = explode("\n",$text); foreach($text AS $val){ $temp_arr=explode("=",$val); $$temp_arr[0][] = $temp_arr[1]; // not sure if this line is correct... }

« previous php.general (#237143) next »