PREG_REPLACE JavaScript
var text = 'test test test test',
fixed;
fixed = text.replace(/\s+/g, '-');
Disgusted Dogfish
var text = 'test test test test',
fixed;
fixed = text.replace(/\s+/g, '-');