mb 함수는 인코딩 형식에 따라 텍스트를 처리하는 함수 확장 입니다.
/etc/php.ini 구성 파일을 수정하고 확장명=php_mbstring.so를 추가하세요
제가 가장 많이 사용하는 substr 함수를 예로 들어보겠습니다. 한눈에 알 수 있습니다.
예:
<span style="color: #008080"> 1</span> <?<span style="color: #000000">php </span><span style="color: #008080"> 2</span> <span style="color: #008000">//</span><span style="color: #008000">phpinfo();</span> <span style="color: #008080"> 3</span> <span style="color: #800080">$str</span> = 'abcdef'<span style="color: #000000">; </span><span style="color: #008080"> 4</span> <span style="color: #0000ff">echo</span> <span style="color: #008080">strlen</span>(<span style="color: #800080">$str</span>);<span style="color: #008000">//</span><span style="color: #008000"> 6</span> <span style="color: #008080"> 5</span> <span style="color: #0000ff">echo</span> '<br/>'<span style="color: #000000">; </span><span style="color: #008080"> 6</span> <span style="color: #0000ff">echo</span> <span style="color: #008080">substr</span>(<span style="color: #800080">$str</span>, 1,2);<span style="color: #008000">//</span><span style="color: #008000"> bc</span> <span style="color: #008080"> 7</span> <span style="color: #0000ff">echo</span> '<br/>'<span style="color: #000000">; </span><span style="color: #008080"> 8</span> <span style="color: #008080"> 9</span> <span style="color: #800080">$str2</span> = '我是谁ab'<span style="color: #000000">; </span><span style="color: #008080">10</span> <span style="color: #0000ff">echo</span> <span style="color: #008080">substr</span>(<span style="color: #800080">$str2</span>, 2, 2);<span style="color: #008000">//</span><span style="color: #008000"> ��</span> <span style="color: #008080">11</span> <span style="color: #0000ff">echo</span> '<br/>'<span style="color: #000000">; </span><span style="color: #008080">12</span> <span style="color: #0000ff">echo</span> mb_substr(<span style="color: #800080">$str2</span>, 2, 2, 'UTF-8');<span style="color: #008000">//</span><span style="color: #008000"> 谁a</span> <span style="color: #008080">13</span> <span style="color: #0000ff">echo</span> '<br/>'<span style="color: #000000">; </span><span style="color: #008080">14</span> <span style="color: #0000ff">echo</span> <span style="color: #008080">strlen</span>(<span style="color: #800080">$str2</span>);<span style="color: #008000">//</span><span style="color: #008000"> 11</span> <span style="color: #008080">15</span> <span style="color: #0000ff">echo</span> '<br/>'<span style="color: #000000">; </span><span style="color: #008080">16</span> <span style="color: #0000ff">echo</span> mb_strlen(<span style="color: #800080">$str2</span>, 'UTF-8');<span style="color: #008000">//</span><span style="color: #008000"> 5</span> <span style="color: #008080">17</span> <span style="color: #0000ff">echo</span> '<br/>';
10행과 12행을 보면 효과가 명확합니다.