Textmate command: url-safe
daniel posted this on Feb 10th 2011 under Textmate commands
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/env 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);
?>