首頁 >後端開發 >php教程 >全角字符轉換為半角字符PHP函數

全角字符轉換為半角字符PHP函數

WBOY
WBOY原創
2016-07-25 08:46:03802瀏覽
  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


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn