<form action="" method="post">
<textarea name="textarea" id="textarea" rows="10" cols="500"><?php echo $_POST['textarea'];?></textarea>
<br>
<input name="mod3" type="radio" id="mod3" value="mod3" checked>
Mod 3
<input type="radio" name="mod3" id="mod2" value="mod2"> 
Mod 2<br>
<input type="submit" name="but1" id="but1" value="Format tsv">
<input type="submit" name="but2" id="but2" value="Format plist">
<input type="submit" name="but3" id="but2" value="Temp Format">
</form>

<?php

if(array_key_exists('but1', $_POST)){
	
	$postdata = $_POST['textarea'];
//	$postdata = str_replace("\r\n", "\r\n\r\n\r\n\r\n\r\n", $postdata);
	
	$postarray = explode("\r\n", $postdata);
	$count = 1;
	
	if($_POST['mod3']=="mod3")
		$mod = 3;
	else
		$mod = 2;
		
	foreach($postarray as $key => $val){
		if($count % $mod == 0){
			$postarray[$key] = $val."\r\n";
		}
		$count++;
	}
	$postdata = implode("\t", $postarray);
	$postdata = str_replace("\r\n\t", "\r\n", $postdata);
	
	?>
<textarea name="textarea" id="textarea" cols="50" rows="10"><?php echo $postdata;?></textarea>
    <?php
}
elseif(array_key_exists('but2', $_POST)){
	
	$postdata = $_POST['textarea'];
//	$postdata = str_replace("\r\n", "\r\n\r\n\r\n\r\n\r\n", $postdata);
	
	
	
	$postarray = explode("\r\n", $postdata);
	
	foreach($postarray as $key => $val){
		$val = explode("\t", $val);
		$val[1] = str_replace("*****", "\r\n  •", $val[1]);
		$val[1] = str_replace("-----", "\r\n    -", $val[1]);
		$val[1] = str_replace("_____", "\r\n(", $val[1]);
		$val[2] = strpos($val[1], "\r\n")==0 ? "" : substr($val[1], strpos($val[1], "\r\n") + 2);
		$val[1] = strpos($val[1], "\r\n")==0 ? $val[1] : substr($val[1], 0, strpos($val[1], "\r\n"));
		$val = "\t<key>$val[0]</key>\r\n\t<array>\r\n\t\t<string>$val[1]</string>\r\n\t\t<string>$val[2]</string>\r\n\t</array>";
		$postarray[$key] = $val;
	}
	
	$postdata = implode("\r\n", $postarray);
	
	?>
<textarea name="textarea" id="textarea" cols="50" rows="10"><?php echo $postdata;?></textarea>
    <?php
}
elseif(array_key_exists('but3', $_POST)){
	
	$postdata = $_POST['textarea'];
	
	/*
	$postdata = str_replace("\r\nï ", "*****", $postdata);
	$postdata = str_replace("\r\no ", "-----", $postdata);
	$postdata = str_replace("\r\n(", "_____", $postdata);
	*/
	
	$postarray = explode("\r\n", $postdata);
	
	foreach($postarray as $key => $val){
		$val = trim($val);//explode("\t", $val);
		$val = str_replace("\t", " ", $val);
		$postarray[$key] = $val;
	}
	
	$postdata = implode("\r\n", $postarray);
	
	?>
<textarea name="textarea" id="textarea" cols="50" rows="10"><?php echo $postdata;?></textarea>
    <?php
}

?>