Thursday, September 14, 2006

converting all newline characters to br tag

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

0 Comments:

Post a Comment

<< Home