PHP to Ruby
Convert PHP code into Ruby!
-
nl2br
Posted on July 4th, 2009 2 commentsThe nl2br() function inserts HTML <br> tags before any new lines in a string.
PHP
echo nl2br("foo has a\n bar"); /* foo has a<br> bar */
Ruby
p "foo has a\n bar".gsub("\n", "<br>\n") # foo has a<br> # bar
2 responses to “nl2br”
-
Your solution does not work.
I always get <br> …. -
RubyLove February 3rd, 2011 at 12:49
the point of this function is to create
tags - when rendered as HTML, these will be line breaks.
Leave a reply
-


