Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • nl2br

    Posted on July 4th, 2009 RubyLove No comments

    The 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

    Leave a reply