converting all newline characters to br tag

Published on Author Akhil Bansal5 Comments

I was surprised as there is no function in ruby to convert all newline characters to <br>.

Here is a php nl2br equivalent method to convert all newline characters (\n) to break tag (<br>) in a string.

 def nl2br(s)
s.gsub(/\\n/, '<br>')
end

5 Responses to converting all newline characters to br tag

Leave a Reply

Your email address will not be published. Required fields are marked *