Reply to Re: [PHP] pasring complex string question

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация