$html_bool = 0;

if ($html_bool == 0){

if( ereg ( "<p " , strtolower($content) ) != 0){

$html_bool =1;

//echo "1";

}

}

if ($html_bool == 0){

if( ereg ( "<td " , strtolower($content) ) != 0){

$html_bool =1;

//echo "2";

}

}

if ($html_bool == 0){

if( ereg ( "</br> " , strtolower($content) ) != 0){

$html_bool =1;

echo "3";

}

}

if ($html_bool == 0){

if( ereg ( "<script " , strtolower($content) ) != 0){

$html_bool =1;

//echo "4";

}

}


if ($html_bool==1){ // html 그냥

    //echo "4";

$content =  nl2br(strip_tags($content));

}

else{ // 일반 <br>

//echo "5";

$content = nl2br($content);

}



ereg 문자열 구분


ereg() 함수 정의 
int eregi(string pattern, string string, array[regs]); 
검색 대상 문자열(string)에서 정규 표현식으로 나타낸 패턴(pattern)과 일치하는 문자열이 발견될 경우에 true 를, 발견되지 않을 경우에는 false를 반환한다.  
이때 대소문자는 구분한다. 



strtolower 영어 문자열을 대문자로 변경


즉 위에 사용되어 있는 if풀어 설명하면

$html_bool==0 일때 ereg로 문자열 찾고 <script,</br>,<p, <td 모든 문자열을 strtolower로 대문자료 변경후에 

문자열이 들어가있으면 $html_bool을 1로 변경 그후 html_bool이 1일경우에 script문자열 방지 strip_tags을 사용해서 script사용 못하게 막아주고 

아닐경우에는 일반적인 정상 br사용되는 nl2br을 사용 


nl2br은 <br>태그 사용 하게 해주는것. 


파일 첨부기능 폼을 만들때 반드시 form 에 enctype="multipart/form-data" 를 넣어 줘야 함.


<form name="form" method="post" enctype="multipart/form-data" action="modify_ok.php?num=<?=$BbsRow[num]?>" ;>

<input type="file" name="FileName">

</form>


# 이거때문에 2시간 모든 코드 파일을 뒤졌음...

<?
header( "Content-type: application/vnd.ms-excel" ); 
header( "Content-type: application/vnd.ms-excel; charset=utf-8");
header( "Content-Disposition: attachment; filename = invoice.xls" ); 
header( "Content-Description: PHP4 Generated Data" );
?>
 
 
<?
$sql = "select * from 테이블명 order by num desc";
$result = mysql_query($sql); // sql에 가져온 정보를 result에 담는다.
// 테이블 상단 만들기
$EXCEL_STR = "
<table border='1'>
<tr>
   <td>번호</td>
   <td>학습동아리명</td>
   <td>회 원 수</td>
   <td>동아리 구분</td>
   <td>연구(학습)과제</td>
   <td>해당분야</td>
   <td>회장 이름</td>
   <td>회장 연락처</td>
   <td>회장 E-mail</td>
   <td>총무 이름</td>
   <td>총무 연락처</td>
   <td>총무 E-mail</td>
   <td>학습동아리 소개</td>
   <td>학급(연구) 목표</td>
   <td>동아리 운영 계획</td>
   <td>학습동아리 기대효과</td>
</tr>";
//위에 talbe은 자신이 가져올 값들의 컬럼 명이 되겠다.
while($row = mysql_fetch_array($result)) {
   $EXCEL_STR .= "
   <tr>
   <td>".$row['num']."</td>
   <td>".$row['jd_name']."</td>
   <td>".$row['jd_member']."명</td>
   <td>".$row['jd_kind']."</td>
   <td>".$row['jd_subject']."</td>
   <td>".$row['jd_filed']."</td>
   <td>".$row['jd_boss1']."</td>
   <td>".$row['jd_boss2']."</td>
   <td>".$row['jd_boss3']."</td>
   <td>".$row['jd_normal1']."</td>
   <td>".$row['jd_normal2']."</td>
   <td>".$row['jd_normal3']."</td>
   <td>".$row['jd_introduce']."</td>
   <td>".$row['jd_goal']."</td>
   <td>".$row['jd_plan']."</td>
   <td>".$row['jd_plus']."</td>   
  
  </tr>
   ";
}
$EXCEL_STR .= "</table>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'> ";
echo $EXCEL_STR;
?>

-------------------------------------------------------------------------------------------------------
매우 어려울지 알았던 DB에 있는 php파일을 엑셀로 저장하기 생각외로 엄청 간단하게 끝이 났다.
주의 할점은
제일 상단에 

<?
header( "Content-type: application/vnd.ms-excel" ); 
header( "Content-type: application/vnd.ms-excel; charset=utf-8");
header( "Content-Disposition: attachment; filename = invoice.xls" ); 
header( "Content-Description: PHP4 Generated Data" );
?>

를 꼭!!!!!! 넣어주어야 한다는 것이다. filename = invoice.xls 말그대로 저장될 파일 명이다. 


+ Recent posts