欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

全角字符转换为半角字符PHP函数

程序员文章站 2024-01-12 17:04:40
...
  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