Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 466 Bytes

File metadata and controls

23 lines (18 loc) · 466 Bytes

nl2br

Adding a <br /> tag before each newline is accomplished in Ruby using string substitution with String#gsub.

{{code:php $result = nl2br("The quick\nbrown fox"); var_export($result); // => "The quick
\nbrown fox" }}

{{code:ruby p "The quick\nbrown fox".gsub("\n", "
\n") # => "The quick
\nbrown fox" }}

{{related: strings/htmlentities strings/htmlspecialchars strings/wordwrap strings/str_replace }}