substr 은 입력받은 문자열을 정해진 길이만큼 잘라서 리턴하는 함수입니다. 


- PHP substr 사용방법 

   substr([문자열], [시작위치], [길이]);

 

ex) substr($row['regdate'],0,10);


regdate-> 2016-06-13 15:49:22 이렇게 DB입력되어 있습니다.


0번째 부터 10개까지 표시

즉 

결과값 ' 2016-01-13 ' 여기까지만 표시 됩니다.


'Front-End > PHP' 카테고리의 다른 글

파일 업로드 오류  (0) 2017.06.05
패이지 처리시  (0) 2017.06.05
PHP문자 <br>태그 적용  (0) 2017.06.05
마우스 우클릭, 드래그, 선택복사, KeyDown 막기  (0) 2017.06.05
영문 , 국문 홈페이지 만들때 주의사항  (0) 2017.06.05

페이지가 다음페이지로 변경 될 때,

코드는 처음부터 다시 실행 된다. (읽는다)

$sc_plan = nl2br($sc_plan); 


 nl2br 함수를 사용 하면 됨.


<body onContextmenu="return false ondragstart="return falseonSelectstart="return false">


[설명]

onkeydown = "return false"  ==> keyDown 금지
oncontextmenu = "return false" ==>  마우스 오른쪽 메뉴 방지
ondragstart = "return false" ==> 드래그 방지
onselectstart = "return false" ==> 선택복사 방지


DB는 공통의로 쓰며 

구축 파일은 En, Kr로 나눠져 있을경우 

파일 업로드시 저장되는 Data폴더가 각각 사용되고 있는지 확인해서 공통으로 사용할수 있도록 바궈 줘야함.

$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 말그대로 저장될 파일 명이다. 


@PathVariable 어노테이션은 Spring에서 제공하는 기능이다.


@PathVariable를 사용하면 URL에서 파라미터를 보내서 사용 할 수 있다.

 

URL호출 

http://localhost:8080/notice/test.do 


 Controller 에서 @RequestMapping 어노테이션안에 {'bbs'} 이런식으로 사용을 하면  

-> @RequestMapping(value = "/notice/{bbs}.do") 


위에 빨간색 부분이 파라미터로 받을 수 있게 만들며

@PathVariable("bbs") String bbs;


@PathVariable을 사용하여 메소드변수에 이런식으로 사용한다.


이때 변수 타입이 맞게 정확한 URL이 입력 되어야 한다. 


@PathVariable("bbs") String bbs; -> @PathVariable("bbs") int bbs; 이면 

URL 입력하는 부분이 문자열이 들어가면 안됨.



사용 방법

Controller에서 


@RequestMapping(value = "/notice/{bbs}.do", method = { RequestMethod.GET, RequestMethod.POST })

public String noticeCallList(HttpServletRequest request, 

     ModelMap map,Model model,@PathVariable("bbs") String bbs){


Systemout.println("bbs 테스트 ::::"+ bbs);

 URL에서 localhost:8080/notice/test.do를 호출 하면

test가 Consol에 찍히는걸 확인 할 수 있을 것이다.





사용 이유 :::: 동일하고 여러개의 컨트롤러를 사용 할 때 유의 함.

응용해서 사용하면 여러가지 폭넓게 계발이 가능함.


'Back-End > Spring' 카테고리의 다른 글

Spring]Injection of resource dependencies failed 에러  (0) 2019.03.10
Context initialization failed 오류  (0) 2018.02.20
Spring 어노테이션 @Resource  (0) 2017.12.13
HashMap  (0) 2017.12.12

파견직 SI업무에 발을 딛을 떄였다.

특급 개발자 프리랜서2분과 같이 일을 하게 되었을때, 나에게 한 말이 있다.


이곳은 정글이야, 스스로 살아남아야지 누군가에게 기대거나 바랄생각이면 당장 그만둬

라는 말을 듣고 나는 곰곰히 생각해보니 너무나 맞는 말이여서

나는 '이곳은 정글이다'라는 생각을 갖고 스스로 노력하여 해처 나가기 위한 다짐?으로 명칭을

'초급개발자 정글에서 살아남기' 라고 지었다.


+ Recent posts