javascript replace spaces with br

JavaScript
str = str.replace(/\s/g, "<br>");
Source

Also in JavaScript: