Archive for the 'Textmate commands' Category

Textmate command: url-safe

Transforms each line in you text file to an url-safe line. I use this for example to transform product names to url-safe names which i can use in a webshop.

#!/usr/bin/php
<?php
$stdin = file_get_contents("php://stdin");

$lines = split("\n", $stdin);
$newlines = array();
foreach($lines as $line) {
$line = strtolower($line);
$line = preg_replace("/\s+/","-",$line);
$line = preg_replace("/[^a-z0-9_\-]/","",$line);
$newlines[] = $line;

}
echo join("\n", $newlines);

?>

No Comments »

Textmate command: sort


#!/usr/bin/php
<?php
$stdin = file_get_contents("php://stdin");
$lines = split("\n", $stdin);
sort($lines);
echo implode("\n", $lines);
?>

No Comments »

Textmate command: lowercase

#!/usr/bin/php
<?php
$stdin = file_get_contents("php://stdin");
echo strtolower($stdin);
?>

No Comments »