textarea에서 쓴 내용 엔터=br 처리된 것처럼 출력되게 하기 질문드립니다.

textarea에서 쓴 내용 엔터=br 처리된 것처럼 출력되게 하기 질문드립니다.

QA

textarea에서 쓴 내용 엔터=br 처리된 것처럼 출력되게 하기 질문드립니다.

본문

<textarea name="wr_content" class="bbs_ft" style="width:90%;height:50; padding:4;" onfocus="clearText(this)" itemname="내용" required="required"></textarea> 
 
소스 중 textarea 입력받는 공간인데요ㅠㅠ 여기서 글을 쓰면 물론 글쓸 때 당시에는 엔터가 쳐지지만
입력 후 내용에 출력되면 그냥 한 줄로만 나타납니다 ㅠㅠ
 
예)
작성공간에는
테스트
테스트
테스트
이렇게 해서 올려도
테스트 테스트 테스트
이런 식으로 엔터 자리가 줄바꿈이 안 되게 나오네요.
 
검색해서 찾아보니까 nl2br를 쓰면 된다는데, 어느 자리에 어떻게 넣어야 할질 모르겠습니다 ㅠㅠ
 
<textarea name="wr_content" class="bbs_ft" style="width:90%;height:50; padding:4;" onfocus="clearText(this)" itemname="내용" required="required"><?=nl2br($wr_content) ?></textarea> 
 
이런식으로 해봤는데 역시 똑같더라구요 ㅠㅠ
 
도와주세요 ㅠ_ㅠ

이 질문에 댓글 쓰기 :

답변 4

뷰페이지에 $content 에 nl2br가 포함돼어 있는걸로 아는데
$content 출력되는곳위에 아래코드를 넣어보세요
$content = nl2br($content);

사용하고 있는 게시판이 메모장 형식이어서 뷰페이지가 따로 없고 리스트 페이지밖에 없어요 ㅠㅠ

<?
if ($w == "") {
$is_name = false;
$is_password = false;

if (!$member[mb_id] || ($is_admin && $w == 'u' && $member[mb_id] != $write[mb_id])) {
$is_name = true;
    $is_password = true;
}

$password_required = "required";
$content = $board[bo_insert_content];

보니까 $content 들어간 건 위처럼 되어있는 곳밖엔 없던데 ㅠㅠ 대체 어떻게 수정해야 할지 ㅠㅠ
초보라서 감이 안 잡히네요 ㅠㅠ

$content = nl2br($board[bo_insert_content]);
입력폼에 옵션 html체크 부분이 없으면
다른 것 필요없고 form에 아래 태그를 추가하세요
<input type="hidden"  name="html" value="html2"

<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

// 이모티콘
function emoticon_html($str, $board_skin_path)
{
$emo_id = "$str";
$img_src = "<img src='$board_skin_path/emoticons/$str.gif' width='18' height='18'

border='0'>";
$str = eregi_replace($emo_id, $img_src, $str);

return $str;
}
?>

<style>

.bbs_form  { margin:0; }
.bbs_linei { background-color:#C0E13A; height:1px; }
.bbs_lineo { background-color:#C0E13A; height:1px; }
.bbs_no    { background-color:#ffffff; height:70px; }
.bbs_fs    { color:#009933; font-size:11px; }
.bbs_jd    { color:#000000; font-size:10pt; font-family:돋움; line-height:120%; }
.bbs_ft   { border-color:#cccccc; border-style:solid; border-width:1px; }
.bbs_tt    { CURSOR:pointer; }

a.bbs:link, a.bbs:visited, a.bbs:active {color:black; text-decoration:none;}
a.bbs:hover { text-decoration:none;  color:#000000; }
img{border:0;} /*링크 걸린 이미지 border 자동 생성*/
a {selector-dummy: expression(this.hideFocus=true);} /*링크 걸린 곳 자동으로 blur주기*/
 
</style>

<script language="JavaScript">
function emo_change(no) {
if ( document.getElementById('emoticon_' + no).style.visibility == "hidden" ) {
    document.getElementById('emoticon_' + no).style.visibility = "visible" ;
    } else {
document.getElementById('emoticon_' + no).style.visibility = "hidden" ;
}
}
function show(no) {
document.getElementById('emoticon_' + no).style.visibility = "visible" ;
}
function hide(no) {
document.getElementById('emoticon_' + no).style.visibility = "hidden" ;
}

function insertSmiley(emo, no, ff){
var skin_path = "<?=$board_skin_path?>";

if(ff) {
ff.mainimage.src = skin_path + "/emoticons/" + emo + ".gif";
ff.wr_subject.value = emo;
document.getElementById('emoticon_' + no).style.visibility = "hidden" ;
}
}

// 글자수 제한
var char_min = parseInt(<?=$write_min?>); // 최소
var char_max = parseInt(<?=$write_max?>); // 최대
</script>

<?
if ($w == "") {
$is_name = false;
$is_password = false;

if (!$member[mb_id] || ($is_admin && $w == 'u' && $member[mb_id] != $write[mb_id])) {
$is_name = true;
    $is_password = true;
}

$password_required = "required";
$content = nl2br($board[bo_insert_content]);

// 글자수 제한 설정값
if ($is_admin)
{
$write_min = $write_max = 0;
}
else
{
    $write_min = (int)$board[bo_write_min];
    $write_max = (int)$board[bo_write_max];
}
include_once("./norobot.inc.php");
}

if (!$subject) $subject = 1;
?>

<form name="ffwrite" method="post" action="javascript:fwrite_check(document.ffwrite);"

enctype="multipart/form-data" autocomplete="off">
<input type=hidden name=w          value="">
<input type=hidden name=bo_table  value="<?=$bo_table?>">
<input type=hidden name=wr_id      value="">
<input type=hidden name=page      value="<?=$page?>">
<input type=hidden name=wr_subject value="<?=$subject?>">
<input type="hidden"  name="html" value="html2">
<? if ($is_password) { ?><input type="hidden" name="wr_password"  value="<?=$norobot_str?>"><? } ?>
<? if ($is_norobot) { ?><input type="hidden" name="wr_key"  value="<?=$norobot_key?>"><? } ?>

<table width="<?=$width?>" align="center" cellpadding="5" cellspacing="0" bgcolor="#ffffff">
<tr>
<td align="center">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
    <td align="center" width="85%">
<textarea name="wr_content" class="bbs_ft" style="width:90%;height:50; padding:4;"

onfocus="clearText(this)" itemname="내용" required="required"></textarea> </td>
<td align="left" width="15%">
<input type="image" id="btn_submit" src="<?=$board_skin_path?>/img/btn_write.gif"

border="0" align="absmiddle"> </td>
</tr>
</table>
</td></tr></table>
</form>

<br>
<br>
<br>

<table width="<?=$width?>" align="center" cellpadding="0" cellspacing="0"><tr><td>
<!-- 게시판 리스트 시작 -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan="6" class="bbs_lineo"></td></tr>
<? for ($i=0; $i<count($list); $i++) {
$list_id = $list[$i][wr_id];
?>
<a name="c_<?=$list_id?>"></a>

<tr>
 <td width="15" height="30" align="center" style="font-size:10px;color:#009933; font-family:verdana">
<? if (!$list[$i][reply]) {?>
<?=$list[$i][num]?>
<?}?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td style="padding : 10px;"><span class="bbs_jd">
<?       
echo $list[$i][reply];
echo $list[$i][icon_reply];
?>
<a href="javascript:list_box('<?=$list_id?>', 'r');" title="RE" class="bbs"><?=$list

[$i][wr_content]?>
</a>&nbsp;&nbsp;&nbsp;
<? if (($member[mb_id] && ($member[mb_id] == $list[$i][mb_id])) || $is_admin) { ?>
<a href="javascript:list_box('<?=$list_id?>', 'u');"><img src="<?=$board_skin_path?

>/img/btn_edit.gif" title="수정" border="0" align="absmiddle"></a><a href="javascript:if (confirm('삭

제하시겠습니까?')) { location='./delete.php?w=d&bo_table=<?=$bo_table?>&wr_id=<?=$list[$i][wr_id]?

>&page=<?=$page?>';}"><img src="<?=$board_skin_path?>/img/btn_del.gif" title="삭제" border="0"

align="absmiddle"></a>
<? } ?> </span></td>

<td width="34">&nbsp;</td>

<td width="60" align="center"><span class="bbs_fs"><?=$list[$i][datetime2]?></span></td>
</tr>
<tr align="left">
<td colspan="6" class="bbs_pp" style="word-break:break-all;">
<img id='save_emoticon_<?=$list_id?>' style='display:none;' border="0" src="<?=

$board_skin_path?>/emoticons/<?=$list[$i][subject]?>.gif">
<input id='save_content_<?=$list_id?>' class="bbs_ft" type=text

style='display:none;width:100%;height:23; padding:4;' value='<?=$list[$i][wr_content]?>'>

<span id='reply_<?=$list_id?>' style='display:none; width:100%;

padding:5;'></span><!-- 답변 -->
<span id='edit_<?=$list_id?>' style='display:none; width:100%;

padding:5;'></span><!-- 수정 --> </td>
</tr>
<tr align="left"><td colspan="6" class="bbs_linei"></td>
</tr>
<? } ?>

<? if (count($list) == 0) { ?>
<tr align="left">
  <td width="170" height="100">&nbsp;</td>
</tr>
<tr><td class="bbs_linei"></td></tr>
<? } ?>
</table>


<!-- 페이지 표시 시작 -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<? if ($write_pages || $prev_part_href || $next_part_href ) { ?>
<tr>
    <td height="50" align="center" valign="middle" class="bbs_no">
<? if ($prev_part_href) { echo "<a href='$prev_part_href'><img

src='$board_skin_path/img/btn_search_prev.gif' width=50 height=20 border=0 align=absmiddle title='이

전검색'></a>"; } ?>
<?
// 기본으로 넘어오는 페이지를 아래와 같이 변환하여 이미지로도 출력할 수 있습니다.
//echo $write_pages;
$write_pages = str_replace("처음", "<img src='$board_skin_path/img/page_first.gif'

border='0' align='absmiddle' title='처음' width='38' height='15'>", $write_pages);
$write_pages = str_replace("이전", "<img src='$board_skin_path/img/page_prev.gif'

border='0' align='absmiddle' title='이전' width='17' height='15'>", $write_pages);
$write_pages = str_replace("다음", "<img src='$board_skin_path/img/page_next.gif'

border='0' align='absmiddle' title='다음' width='17' height='15'>", $write_pages);
$write_pages = str_replace("맨끝", "<img src='$board_skin_path/img/page_end.gif'

border='0' align='absmiddle' title='맨끝' width='38' height='15'>", $write_pages);
$write_pages = preg_replace("/<span>([0-9]*)<\/span>/", "<font style=\"font-family:돋

움; font-size:9pt; color:#000000\">$1</font>", $write_pages);
$write_pages = preg_replace("/<b>([0-9]*)<\/b>/", "<font style=\"font-family:돋움;

font-size:9pt; color:orange;\">$1</font>", $write_pages);
?>
<?=$write_pages?>
<? if ($next_part_href) { echo "<a href='$next_part_href'><img

src='$board_skin_path/img/btn_search_next.gif' width=50 height=20 border=0 align=absmiddle title='다

음검색'></a>"; } ?><br />
<!-- 검색&버튼 -->
<div style="float:center;height:26px;">
<table width="250" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td><form name="fsearch" method="get">
        <input type="hidden" name="bo_table" value="<?=$bo_table?>">
        <input type="hidden" name="sca" value="<?=$sca?>">
        <select name="sfl" class="sel">
            <option value="wr_subject">제목</option>
            <option value="wr_content">내용</option>
            <option value="wr_subject||wr_content">제목+내용</option>
            <option value="mb_id,1">아이디</option>
            <option value="mb_id,0">아이디(코)</option>
            <option value="wr_name,1">글쓴이</option>
            <option value="wr_name,0">글쓴이(코)</option>
        </select></td>
    <td><div class="bbs_searchbox"><input name="stx" class="bbs_search" maxlength="33" itemname="검색

어" required value='<?=stripslashes($stx)?>'>&nbsp;<input type="image" src="<?=$board_skin_path?

>/img/btn_search.gif" border='0' align="absmiddle"></div>
</form></td>
  </tr>
</table>
</div>

</td>
</tr>
<? } ?>
<tr><td></td></tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="" height="40">
<? if ($admin_href) { ?><a href='<?=$admin_href?>' target="_blank"><img src="<?=

$board_skin_path?>/img/btn_admin.gif" border="0" width="55" height="20" align="absmiddle" title="관리

자"></a><? } ?>
</td>
</tr>
</table>
</td></tr></table>

<span id=list_write style='display:none; width:100%; padding:10;'>
<form name="fwrite" method="post" action="javascript:fwrite_check(document.fwrite);"

enctype="multipart/form-data" autocomplete="off">
<input type=hidden name=w          value="" id="list_w">
<input type=hidden name=bo_table  value="<?=$bo_table?>">
<input type=hidden name=wr_id      value="<?=$list[$i][wr_id]?>" id="list_id">
<input type=hidden name=page      value="<?=$page?>">
<input type=hidden name=wr_subject value="<?=$subject?>">
<input type="hidden"  name="html" value="html2">
<? if ($is_password) { ?><input type="hidden" name="wr_password"  value="<?=$norobot_str?>"><? } ?>
<? if ($is_norobot) { ?><input type="hidden" name="wr_key"  value="<?=$norobot_key?>"><? } ?>


<table width="<?=$width?>" align="center" cellpadding="5" cellspacing="0" bgcolor="#ffffff"><tr><td

align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td width="20" class="bbs_tt" style="padding-top:3px;">
<img id="list_image" name="mainimage" border="0" src="<?=$board_skin_path?

>/emoticons/<?=$subject?>.gif"><br>
</td>
<td width="10"></td>
<td align="left">
<textarea name="wr_content" class="bbs_ft" id="list_content"

style="width:100%;height:50; padding:4;" onfocus="clearText(this)" itemname="내용"

required="required"></textarea>
</td>
<td width="10"></td>
<? if ($is_name) { ?>
<td width="80">
<input class="bbs_ft" maxLength="20" size="13" name="wr_name" itemname="이름"

required style="height:23; padding:4;" value="손님" onFocus="clearText(this)">
</td>
<td width="10"></td>
<? } ?>
<td width="30">
<input type="image" id="btn_submit" src="<?=$board_skin_path?>/img/btn_write.gif"

border="0" align="absmiddle">
</td>
</tr>
</table>
</td></tr></table>
</form>
</span>

<script language="Javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value) thefield.value = "";
}

function fwrite_check(f)
{
    var s = "";
if (f.wr_content.value == "내용을 써야디ㅠㅠ"){
alert("내용을 써야디ㅠㅠ")
return;
}

if (s = word_filter_check(f.wr_content.value)) {
        alert("내용에 금지단어('"+s+"')가 포함되어있습니다");
        return;
}

    f.action = "./write_update.php";
    f.submit();
}

var old_id, new_id;
var save_html = document.getElementById('list_write').innerHTML;

function list_box(list_id, work)
{
// 답변, 수정
    if (list_id)
    {
        if (work == 'r')
            new_id = 'reply_' + list_id;
        else
            new_id = 'edit_' + list_id;
    }
    else
        new_id = 'list_write';

if (old_id == new_id) {
var mode = document.getElementById(new_id).style.display;
if (mode == 'inline')
document.getElementById(new_id).style.display = 'none';
else
document.getElementById(new_id).style.display = 'inline';
}
else
    {
        if (old_id)
        {
            document.getElementById(old_id).style.display = 'none';
            document.getElementById(old_id).innerHTML = '';
        }

        document.getElementById(new_id).style.display = 'inline';
document.getElementById(new_id).innerHTML = save_html;

// 수정
        if (work == 'u')
        {
document.getElementById('list_image').src = document.getElementById

('save_emoticon_' + list_id).src;
document.getElementById('list_content').value = document.getElementById

('save_content_' + list_id).value;
        }

        document.getElementById('list_id').value = list_id;
        document.getElementById('list_w').value = work;
old_id = new_id;
}
}

list_box('', '');
new_id = 'list_write';
document.getElementById(new_id).style.display = 'none';
</script>

<?
if ($w == "") {
if (!$member[mb_id])
    echo "<script language='javascript' src='$g4[path]/js/md5.js'></script>\n";

// 필터
echo "<script language='javascript'> var g4_cf_filter = '$config[cf_filter], '; </script>\n";
echo "<script language='javascript' src='$g4[path]/js/filter.js'></script>\n";
}
?>

===================================여기까지 list.skin.php 끝=======================================
위에가 소스 전문입니다. 알려주셨던 두 가지
$content = nl2br($board[bo_insert_content]);  와
<input type="hidden"  name="html" value="html2"> 까지
모두 해봤는데도 계속 안 되네요ㅋㅋㅋㅋ 휴..
알려주셔서 감사합니다 ㅠ_ㅠ

답변을 작성하시기 전에 로그인 해주세요.
전체 125,888 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT