Home > php教程 > php手册 > php将字符串中全角字符转换为半角字符

php将字符串中全角字符转换为半角字符

WBOY
Release: 2016-06-13 09:04:30
Original
918 people have browsed it

php将字符串中全角字符转换为半角字符

php将字符串中全角字符转换为半角字符,摘自ecshop。

/**
 * 将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符
 * @access  public
 * @param   string       $str         待转换字串
 * @return  string       $str         处理后字串
 */

function make_semiangle($str){
    $arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
                 '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
                 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',
                 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',
                 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
                 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',
                 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',
                 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',
                 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',
                 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',
                 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',
                 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',
                 'y' => 'y', 'z' => 'z',
                 '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',
                 '】' => ']', '〖' => '[', '〗' => ']', '"' => '[', '"' => ']',
                 '\'' => '[', '\'' => ']', '{' => '{', '}' => '}', '《' => '<',
                 '》' => '>',
                 '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',
                 ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',
                 ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',
                 '"' => '"', '\'' => '`', '\'' => '`', '|' => '|', '〃' => '"',
                 ' ' => ' ');
    return strtr($str, $arr);
}
Copy after login

您可能感兴趣的文章

  • php 将字符串中的连续多个空格转换为一个空格
  • php如何将html中的br换行符转换为文本输入中的换行符
  • js如何将返回的字符串转换为json格式的数据
  • Mysql查询带单引号字符串及插入带单引号字符串需要注意问题
  • php判断字符串是否全英文,纯中文,中英文组合的方法
  • php 函数将16进制颜色代码转换为 RGB 色值
  • php获取utf8字符串的字符长度
  • js数组转字符串,js字符串转数组的方法总结
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template