Re: [PHP] Re: Parse string with variables
On 5/31/06, Barry <[EMAIL PROTECTED]> 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... } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Parse string with variables
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 -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: parse string
Hi Ron, Not aware of an existing function for that task... but - since it looks like all the value are strictly in quotes (="value") - if you know all the 'var's ahead of time (such as 'carrier') then you could extract the data fairly easily going through the data line by line checking with strpos and using substr to get the values... it'll take some work, but it'll do the job... Cheers, Ben -Original Message- From: Ron Eggler (Paykiosks) [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 18, 2006 2:12 PM To: php-general@lists.php.net Subject: parse string Hi, I need to parse a String like pasted below for all information (values) those are included like 'var=value'. How can I do that? Are there any XML-parsing functions available those'd fit for that job? I've ust found that one (http://ca.php.net/simplexml) but it seems like i could use it only for exctracting the 'terms' cause they're in the format that simplexml expects. Thank you for every help! [String] https://www.pinsprepaid.com/image.aspx?name=c38-reconex_logo.gif"; /> https://www.pinsprepaid.com/image.aspx?name="; /> https://www.pinsprepaid.com/image.aspx?name="; /> https://www.pinsprepaid.com/image.aspx?name=PlayPhone-200x100.gif"; /> https://www.pinsprepaid.com/image.aspx?name=PayGo_200_100.gif"; /> https://www.pinsprepaid.com/image.aspx?name="; /> https://www.pinsprepaid.com/image.aspx?name="; /> https://www.pinsprepaid.com/image.aspx?name="; /> https://www.pinsprepaid.com/image.aspx?name=c59-BoostMobile.gif"; /> https://www.pinsprepaid.com/image.aspx?name=cing-blue.gif"; /> https://www.pinsprepaid.com/image.aspx?name=pageplus.gif"; /> https://www.pinsprepaid.com/image.aspx?name=c29-t-mobile_ticketlogo.gi f" /> https://www.pinsprepaid.com/image.aspx?name=unefon_logo.gif"; /> https://www.pinsprepaid.com/image.aspx?name=verizon.gif"; /> https://www.pinsprepaid.com/image.aspx?name=Virgin+Mobile +200x100.gif" /> https://www.pinsprepaid.com/image.aspx?name=c38-reconex_logo.gif"; upc="870368000420"> Refer to the Reconex brochure for complete terms and conditions. https://www.pinsprepaid.com/image.aspx?name=c38-reconex_logo.gif"; upc="870368000437"> Refer to the Reconex brochure for complete terms and conditions. https://www.pinsprepaid.com/image.aspx?name=c38-reconex_logo.gif"; upc="870368000413"> Refer to the Reconex brochure for complete terms and conditions. https://www.pinsprepaid.com/image.aspx?name=c38-reconex_logo.gif"; upc="870368000406"> Refer to the Reconex brochure for complete terms and conditions. [/String] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php