Contents

Develop
2015.11.10 15:51

[php] 한글 문자열 자르기 (utf-8)

조회 수 1328 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

그누보드/lib/common.lib.php line 890 

// 한글 한글자(2byte)는 길이 2, 공란.영숫자.특수문자는 길이 1 

function cut_str($str, $len, $suffix="…") 
{
    // 여기 추가,
    $s = iconv_substr($str, 0, $len, "utf-8");

    // 아래 주석처리 ! 
    //$s = substr($str, 0, $len); 
    //$cnt = 0; 
    //for ($i=0; $i<strlen($s); $i++) 
    //    if (ord($s[$i]) > 127) 
    //        $cnt++; 
    //$s = substr($s, 0, $len - ($cnt % 2)); 
    
    if (strlen($s) >= strlen($str))
        $suffix = ""; 
        
    return $s . $suffix; 
}

 

* 참고: PHP5에 iconv_substr( string str, int offset [, int length [, string charset]] ) 내장되었네요. 
* utf-8 적용시 cut_str()으로 잘 안될 때가 있어서 수정해봤습니다.


?

  1. [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기

    Date2021.01.29 CategoryDevelop Byhooni Views1392
    Read More
  2. [swift] NotificationCenter 간단 예제

    Date2021.01.27 CategoryDevelop Byhooni Views8125
    Read More
  3. [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories)

    Date2015.01.02 CategorySystem/OS Byhooni Views1551
    Read More
  4. [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때..

    Date2013.09.25 CategoryEtc Byhooni Views37506
    Read More
  5. [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback)

    Date2014.11.27 CategorySystem/OS Byhooni Views1568
    Read More
  6. [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우

    Date2014.12.18 CategorySystem/OS Byhooni Views995
    Read More
  7. [sql] 한눈에 보이는 Join

    Date2014.02.19 CategoryDatabase Byhooni Views8470
    Read More
  8. [sql] 쿼리로 문자열 검색해서 일괄 치환하기

    Date2014.02.13 CategoryDatabase Byhooni Views9976
    Read More
  9. [sql] 중복데이터 삭제 쿼리

    Date2013.04.23 CategorySystem/OS Byhooni Views14739
    Read More
  10. [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct)

    Date2013.04.23 CategorySystem/OS Byhooni Views33945
    Read More
  11. [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문)

    Date2003.04.23 CategorySystem/OS Byhooni Views12845
    Read More
  12. [sql] 간단한 통계 서브쿼리 예제..

    Date2013.04.23 CategoryDatabase Byhooni Views15091
    Read More
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 ... 98 Next
/ 98