Home  >  Article  >  Backend Development  >  Convert full-width characters to half-width characters PHP function

Convert full-width characters to half-width characters PHP function

WBOY
WBOYOriginal
2016-07-25 08:46:03720browse
  1. /**
  2. * 全角字符转换为半角字符
  3. */
  4. function make_semiangle ( $str )
  5. {
  6. $arr = array ( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
  7. '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
  8. 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',
  9. 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',
  10. 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
  11. 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',
  12. 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',
  13. 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',
  14. 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',
  15. 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',
  16. 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',
  17. 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',
  18. 'y' => 'y', 'z' => 'z',
  19. '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',
  20. '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',
  21. '‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<', '》' => '>',
  22. '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',
  23. ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',
  24. ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',
  25. '”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',
  26. ' ' => ' ' );
  27. return strtr ( $str, $arr );
  28. }
复制代码

转换为, PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn