Knowledge Base

January 31, 2008

Display textarea content with line breaks in html page

Filed under: Technical — Tags: , , , — rkutti @ 12:21 pm

Let us see how javascript, php, and ruby display the content of textarea with line breaks

Javascript:

document.getElemnetById(‘textareacontent’).value.replace(/\n/g,’<br>’);

PHP:

preg_replace(“/\n/”,”<br>”,$_REQUEST['t1']);

Ruby:

(teaxtareacontent).gsub(/\n/,”<br>”)

Blog at WordPress.com.