$value) { if(is_array($value)) $content .= _tab_to_str($pre.strlen($key).":".$key, $TAB[$key]); else $content .= $pre.strlen($key).":".$key.strlen($value).":".$value."\n"; } } else return $pre."a:\n"; return $content; } function str_to_tab($content) { $TAB = array(); $n = 0; while($n < strlen($content)) { $LINE_FOUND = 0; $ENDS_WITH_EMPTY_TAB = 0; $words = array(); while($n < strlen($content) && !$LINE_FOUND) { $length = ""; $word = ""; while($n < strlen($content) && strcmp(substr($content, $n, 1), ":") != 0) { $length .= $content[$n]; $n++; } $n++; if(strcmp($length, "a") == 0) $ENDS_WITH_EMPTY_TAB = 1; else { for($k = 0; $k < $length; $k++) { $word .= $content[$n]; $n++; } $words[] = $word; } $LINE_FOUND = $ENDS_WITH_EMPTY_TAB || $n == strlen($content) || strcmp(substr($content, $n, 1), "\n") == 0; } $n++; if($words) $TAB = affect($TAB, $words, $ENDS_WITH_EMPTY_TAB); } return $TAB; } function affect($TAB, $words, $ENDS_WITH_EMPTY_TAB) { if(count($words) > ($ENDS_WITH_EMPTY_TAB ? 1 : 2)) { if(!is_array($TAB[$words[0]])) $TAB[$words[0]] = array(); $_words = array(); $FIRST = 1; foreach($words as $word) { if($FIRST) $FIRST = 0; else $_words[] = $word; } $TAB[$words[0]] = affect($TAB[$words[0]], $_words, $ENDS_WITH_EMPTY_TAB); } else $TAB[$words[0]] = ($ENDS_WITH_EMPTY_TAB ? array() : $words[1]); return $TAB; } ?>