title: Why can't change all the characters from full width character into half width character?
body: <p>I want to change all the characters  from full width characters into half width characters, write the following codes  to do the job.
  For example, to change all full width characters in </p>
  
  <pre><code> Ｃｏｄｅｂｉｔ.ｃｎ － 聚合小段精华代码 
  </code></pre>
  
  <p>into half width characters ,into</p>
  
  <pre><code> codebit.cn - 聚合小段精华代码
  </code></pre>
  
  <p>There are two methods to acheive the goal,but all of them failed.<br>
  All the php file were saved as utf-8 format.</p>
  
  <p>method 1:</p>
  
  <pre><code>&lt;?php
      function fulltohalf($str){
      $arr=Array( 
      '０' =&gt; '0', '１' =&gt; '1', '２' =&gt; '2', '３' =&gt; '3', '４' =&gt; '4',  
      '５' =&gt; '5', '６' =&gt; '6', '７' =&gt; '7', '８' =&gt; '8', '９' =&gt; '9', 
      'Ａ' =&gt; 'A', 'Ｂ' =&gt; 'B', 'Ｃ' =&gt; 'C', 'Ｄ' =&gt; 'D', 'Ｅ' =&gt; 'E',  
      'Ｆ' =&gt; 'F', 'Ｇ' =&gt; 'G', 'Ｈ' =&gt; 'H', 'Ｉ' =&gt; 'I', 'Ｊ' =&gt; 'J', 
      'Ｋ' =&gt; 'K', 'Ｌ' =&gt; 'L', 'Ｍ' =&gt; 'M', 'Ｎ' =&gt; 'N', 'Ｏ' =&gt; 'O',  
      'Ｐ' =&gt; 'P', 'Ｑ' =&gt; 'Q', 'Ｒ' =&gt; 'R', 'Ｓ' =&gt; 'S', 'Ｔ' =&gt; 'T', 
      'Ｕ' =&gt; 'U', 'Ｖ' =&gt; 'V', 'Ｗ' =&gt; 'W', 'Ｘ' =&gt; 'X', 'Ｙ' =&gt; 'Y',  
      'Ｚ' =&gt; 'Z', 'ａ' =&gt; 'a', 'ｂ' =&gt; 'b', 'ｃ' =&gt; 'c', 'ｄ' =&gt; 'd', 
      'ｅ' =&gt; 'e', 'ｆ' =&gt; 'f', 'ｇ' =&gt; 'g', 'ｈ' =&gt; 'h', 'ｉ' =&gt; 'i',  
      'ｊ' =&gt; 'j', 'ｋ' =&gt; 'k', 'ｌ' =&gt; 'l', 'ｍ' =&gt; 'm', 'ｎ' =&gt; 'n', 
      'ｏ' =&gt; 'o', 'ｐ' =&gt; 'p', 'ｑ' =&gt; 'q', 'ｒ' =&gt; 'r', 'ｓ' =&gt; 's',  
      'ｔ' =&gt; 't', 'ｕ' =&gt; 'u', 'ｖ' =&gt; 'v', 'ｗ' =&gt; 'w', 'ｘ' =&gt; 'x', 
      'ｙ' =&gt; 'y', 'ｚ' =&gt; 'z', '－' =&gt; '-' 
      ); 
  
      $new = '';            
      foreach ($str as $char){
          if (isset ($arr[$char]))  
              $new .= $arr[$char];    
          else
              $new .= $arr;    
          }
      return $new;
      }
  
  $str="Ｃｏｄｅｂｉｔ.ｃｎ － 聚合小段精华代码";
  echo fulltohalf($str);
  ?&gt;
  </code></pre>
  
  <p>Error message:</p>
  
  <p><img src="https://i.stack.imgur.com/DE7Mw.png" alt="enter image description here"></p>
  
  <p>method 2: </p>
  
  <pre><code>&lt;?php
  function fulltohalf($Str) { 
      $Queue = Array( 
      '０' =&gt; '0', '１' =&gt; '1', '２' =&gt; '2', '３' =&gt; '3', '４' =&gt; '4',  
      '５' =&gt; '5', '６' =&gt; '6', '７' =&gt; '7', '８' =&gt; '8', '９' =&gt; '9', 
      'Ａ' =&gt; 'A', 'Ｂ' =&gt; 'B', 'Ｃ' =&gt; 'C', 'Ｄ' =&gt; 'D', 'Ｅ' =&gt; 'E',  
      'Ｆ' =&gt; 'F', 'Ｇ' =&gt; 'G', 'Ｈ' =&gt; 'H', 'Ｉ' =&gt; 'I', 'Ｊ' =&gt; 'J', 
      'Ｋ' =&gt; 'K', 'Ｌ' =&gt; 'L', 'Ｍ' =&gt; 'M', 'Ｎ' =&gt; 'N', 'Ｏ' =&gt; 'O',  
      'Ｐ' =&gt; 'P', 'Ｑ' =&gt; 'Q', 'Ｒ' =&gt; 'R', 'Ｓ' =&gt; 'S', 'Ｔ' =&gt; 'T', 
      'Ｕ' =&gt; 'U', 'Ｖ' =&gt; 'V', 'Ｗ' =&gt; 'W', 'Ｘ' =&gt; 'X', 'Ｙ' =&gt; 'Y',  
      'Ｚ' =&gt; 'Z', 'ａ' =&gt; 'a', 'ｂ' =&gt; 'b', 'ｃ' =&gt; 'c', 'ｄ' =&gt; 'd', 
      'ｅ' =&gt; 'e', 'ｆ' =&gt; 'f', 'ｇ' =&gt; 'g', 'ｈ' =&gt; 'h', 'ｉ' =&gt; 'i',  
      'ｊ' =&gt; 'j', 'ｋ' =&gt; 'k', 'ｌ' =&gt; 'l', 'ｍ' =&gt; 'm', 'ｎ' =&gt; 'n', 
      'ｏ' =&gt; 'o', 'ｐ' =&gt; 'p', 'ｑ' =&gt; 'q', 'ｒ' =&gt; 'r', 'ｓ' =&gt; 's',  
      'ｔ' =&gt; 't', 'ｕ' =&gt; 'u', 'ｖ' =&gt; 'v', 'ｗ' =&gt; 'w', 'ｘ' =&gt; 'x', 
      'ｙ' =&gt; 'y', 'ｚ' =&gt; 'z', '－' =&gt; '-' 
  ); 
  
  return preg_replace("/([\xA3][\xB0-\xB9\xC1-\xDA\xE1-\xFA])/e","\$Queue[\\1]", $Str); 
  </code></pre>
  
  <p>} </p>
  
  <pre><code>$str = "Ｃｏｄｅｂｉｔ.ｃｎ － 聚合小段精华代码"; 
  echo $str; 
  echo "&lt;br /&gt;"; 
  echo fulltohalf($str); 
  ?&gt;
  </code></pre>
  
  <p>Error message:</p>
  
  <p><img src="https://i.stack.imgur.com/QRdAr.png" alt="enter image description here"></p>
  
  <p>How to fix two of them?</p>
  
  <p>I solved the method 1 problem ,the fixed codes are as the following.</p>
  
  <pre><code>&lt;?php
  function fulltohalf($str){
  $arr=Array( 
  '０' =&gt; '0', '１' =&gt; '1', '２' =&gt; '2', '３' =&gt; '3', '４' =&gt; '4',  
  '５' =&gt; '5', '６' =&gt; '6', '７' =&gt; '7', '８' =&gt; '8', '９' =&gt; '9', 
  'Ａ' =&gt; 'A', 'Ｂ' =&gt; 'B', 'Ｃ' =&gt; 'C', 'Ｄ' =&gt; 'D', 'Ｅ' =&gt; 'E',  
  'Ｆ' =&gt; 'F', 'Ｇ' =&gt; 'G', 'Ｈ' =&gt; 'H', 'Ｉ' =&gt; 'I', 'Ｊ' =&gt; 'J', 
  'Ｋ' =&gt; 'K', 'Ｌ' =&gt; 'L', 'Ｍ' =&gt; 'M', 'Ｎ' =&gt; 'N', 'Ｏ' =&gt; 'O',  
  'Ｐ' =&gt; 'P', 'Ｑ' =&gt; 'Q', 'Ｒ' =&gt; 'R', 'Ｓ' =&gt; 'S', 'Ｔ' =&gt; 'T', 
  'Ｕ' =&gt; 'U', 'Ｖ' =&gt; 'V', 'Ｗ' =&gt; 'W', 'Ｘ' =&gt; 'X', 'Ｙ' =&gt; 'Y',  
  'Ｚ' =&gt; 'Z', 'ａ' =&gt; 'a', 'ｂ' =&gt; 'b', 'ｃ' =&gt; 'c', 'ｄ' =&gt; 'd', 
  'ｅ' =&gt; 'e', 'ｆ' =&gt; 'f', 'ｇ' =&gt; 'g', 'ｈ' =&gt; 'h', 'ｉ' =&gt; 'i',  
  'ｊ' =&gt; 'j', 'ｋ' =&gt; 'k', 'ｌ' =&gt; 'l', 'ｍ' =&gt; 'm', 'ｎ' =&gt; 'n', 
  'ｏ' =&gt; 'o', 'ｐ' =&gt; 'p', 'ｑ' =&gt; 'q', 'ｒ' =&gt; 'r', 'ｓ' =&gt; 's',  
  'ｔ' =&gt; 't', 'ｕ' =&gt; 'u', 'ｖ' =&gt; 'v', 'ｗ' =&gt; 'w', 'ｘ' =&gt; 'x', 
  'ｙ' =&gt; 'y', 'ｚ' =&gt; 'z', '－' =&gt; '-' 
  ); 
  
  $new = '';
  preg_match_all('/./u', $str, $results);
  $str=$results[0];            
  foreach ($str as $char){
      if (isset ($arr[$char]))  
          $new .= $arr[$char];    
      else
          $new .= $char;   
      }
  return $new;
  }
  
  echo fulltohalf("Ｃｏｄｅｂｉｔ.ｃｎ － 聚合小段精华代码");
  ?&gt;
  </code></pre>