[TxMt] Unwanted newline php

Ryan Fitzer ryanfitzer at gmail.com
Fri Dec 11 06:31:11 UTC 2009


I'm writing a command using php that reorders a css property list by
string length. The problem I'm having is that a newline character is
being added at the beginning of the result for some reason (using
Replace selected text). I've consulted this thread
http://lists.macromates.com/textmate/2007-April/019068.html but I've
found no way of echoing a string without the newline being added. Here
is the command:

#!/usr/bin/php

<?php

$fstat = fstat(STDIN);
$stdin = fread(STDIN, $fstat['size']);

//print_r($stdin);

$pattern = '/\{(.*)\}/Us';
preg_match($pattern, $stdin, $matches);
$output = trim($matches[1], "\n");
$output = preg_split('/\n/', $output);

function sort_strlength($val_1, $val_2) {
	// initialize the return value to zero
	$retVal = 0;

	// compare lengths
	$firstVal = strlen($val_1);
	$secondVal = strlen($val_2);

	if($firstVal > $secondVal) {
		$retVal = 1;
	} else if($firstVal < $secondVal) {
		$retVal = -1;
	}
	
	return $retVal;
}

uasort($output, "sort_strlength");

$out = '{' . "\n";
foreach($output as $line) {
	$out .= $line . "\n";
}	
$out .= '}';

print(trim($out));

?>

Any help would be appreciated.

Ryan

-- 
Ryan Fitzer
Los Angeles, CA
http://www.ryanfitzer.com
http://www.portfoliorodeo.com



More information about the textmate mailing list