|
Posted by Richard Lynch on 04/09/05 00:01
On Thu, April 7, 2005 5:32 pm, Webmaster said:
> ## /T (KEY1)/V (VALUE1)|| ## /T (KEY2)/V (VALUE2)|| ## /V (VALUE3)/T
> (KEY3)||
>
> I know want to separete it in to keys and values and insert them into an
> array.
>
> Note that /T always shows that teh upcoming value in() is a Key and that
> /V
> always is a Value. And that the set can be flipped.
Question #1:
What happens when your KEY or VALUE contains "##", "/T", or "/V"
Depending on your answer to that, the best solution will change a bit.
In the short term:
$string = "## /T (KEY1)/V (VALUE1)|| ## /T (KEY2)/V (VALUE2)|| ## /V
(VALUE3)/T (KEY3)|| ";
$keyvalues = explode("##", $string);
$answer = array();
while (list(, $keyvalue) = each($keyvalues)){
$keyvalue = trim($keyvalue);
if (substr($keyvalue, 0, -2) != '||'){
die("Unexpected keyvalue: $keyvalue");
}
$keyvalue = substr($keyvalue, 0, -2);
preg_match("#/T(.*)(/V|$)#", $keyvalue, $key);
$key = $key[1];
preg_match("#/V(.*)(/T|$)#", $keyvalue, $value);
$value = $value[1];
$answer[$key] = $value;
}
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|