Contents

조회 수 21530 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
PHP의 substr() 함수를 쓸 때 한글이 깨지는 경우가 있다.
이런 경우 아래와 같은 함수로 대체하면 된다.

1. PHP 4.0 이상을 쓰면 mb_substr()을 이용
mb_substr($str, 0, 10, 'EUC-KR');
또는
mb_substr($str, 0, 10, 'UTF-8');

 
2. 그 외는 아래 함수를 작성해서 이용
function trim_str($str, $length) {
    if (!$str) return '';
    preg_match('/^([\xa1-\xfe]{2}|.){'.$length.'}/s', $str, $tmp_str);
    return (!$tmp_str[0]) ? $str : ($tmp_str[0].'...');
}


?

  1. [php] substr() 한글 자를 때 깨짐 방지

    Date2014.01.09 CategoryDevelop Byhooni Views21530
    Read More
  2. [linux] iconv를 이용하여 euc-kr 문서를 utf-8로 대량으로 변환하기

    Date2014.01.09 CategorySystem/OS Byhooni Views13428
    Read More
  3. [ios] UIButton multi-line iOS7

    Date2014.01.09 CategoryDevelop Byhooni Views13582
    Read More
  4. iOS 에서 쓸만한 오프라인 구글지도 찾기

    Date2014.01.06 CategoryEtc Byhooni Views17283
    Read More
  5. [js] AngularJS를 소개합니다.

    Date2014.01.06 CategoryDevelop Byhooni Views13844
    Read More
  6. [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미

    Date2014.01.02 CategoryEtc Byhooni Views43217
    Read More
  7. [php] 하루 전 날짜 쉽게 구하기.

    Date2013.12.25 CategoryDevelop Byhooni Views13591
    Read More
  8. [php] GregorianToJD(), JDToGregorian() 함수 내용

    Date2013.12.25 CategoryDevelop Byhooni Views11551
    Read More
  9. [linux] root 전환시 패스워드 없이 su 사용하기

    Date2013.12.22 CategorySystem/OS Byhooni Views13633
    Read More
  10. [linux] CentOS 터미널 언어 설정(한글/영어)

    Date2013.12.22 CategorySystem/OS Byhooni Views19554
    Read More
  11. [js] jQuery plugin 요약

    Date2013.12.20 CategoryDevelop Byhooni Views11585
    Read More
  12. [css] z-index에 설정할 수 있는 최대값?

    Date2013.12.20 CategoryDevelop Byhooni Views15952
    Read More
Board Pagination Prev 1 ... 24 25 26 27 28 29 30 31 32 33 ... 99 Next
/ 99