"Nl2br()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
3번째 줄: 3번째 줄:
==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
function nl2br(str){   
function nl2br(str){   
     return str.replace(/\n/g, "<br />");   
     return str.replace(/\n/g, "<br />");   
10번째 줄: 10번째 줄:
console.log( nl2br("Hello\nWorld") );
console.log( nl2br("Hello\nWorld") );
// Hello<br />World
// Hello<br />World
</source>
</syntaxhighlight>
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
function nl2br(str){   
function nl2br(str){   
     return str.replace(/\n/g, "<br />\n");   
     return str.replace(/\n/g, "<br />\n");   
19번째 줄: 19번째 줄:
// Hello<br />
// Hello<br />
// World
// World
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
$result = nl2br("Hello\nWorld");
$result = nl2br("Hello\nWorld");


31번째 줄: 31번째 줄:
echo strlen( $result );
echo strlen( $result );
# 17
# 17
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:34 기준 최신판

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 }}