Nl2br()

Jmnote (토론 | 기여)님의 2015년 9월 7일 (월) 18:51 판 (→‎JavaScript)
nl2br()

1 JavaScript

function nl2br(str){  
    return str.replace(/\n/g, "<br />");  
}  

console.log( nl2br("Hello\nWorld") );
// Hello<br />World
function nl2br(str){  
    return str.replace(/\n/g, "<br />\n");  
}  

console.log( nl2br("Hello\nWorld") );
// Hello<br />
// World

2 PHP

$result = nl2br("Hello\nWorld");

echo $result;
# Hello<br />
# World
echo strlen( $result );
# 17

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}