Verbose Unix commands by default (rm/cp/mkdir/etc)

If you want to see output of what these commands is doing, you can add the optional "-v" flag.

Or, you can add this to your .bash_profile (or whatever shell you're using)

alias cp='/bin/cp -v'
alias mv='/bin/mv -v'
alias rm='/bin/rm -v'
alias mkdir='/bin/mkdir -v'
alias rmdir='/bin/rmdir -v'

 

November 16, 2011 at 02:03:18 PM / 1 comments / Linux

PHP function to create SEO friendly URL, Unix friendly file names

This is a useful function for creating SEO friendly URL's.  It's also handy for creating Unix friendly file names.  

It simply removes anything that isn't a number or a letter and replaces it with a hypen (or any other character you pass... such as an underscore.) 

function seome($str, $char = '-')
{
  // convert non-alphanumeric to dashes
  $str = preg_replace("([^A-Za-z0-9])", $char, $str);

  // replace 2 or more dashes with single dashes
  $str = preg_replace("/(-){2,}/m", $char, $str);

  // remove any trailing or leading dashes
  $str = trim($str, $char);

  return $str;
}

November 6, 2011 at 04:47:44 PM / 1 comments / Code, General Web Programming, PHP