首页 >后端开发 >php教程 >php 中全半角转换

php 中全半角转换

WBOY
WBOY原创
2016-07-30 13:29:26914浏览
// 半角数组 
$half = array(
   '0','1','2','3','4','5',
   '6','7','8','9','a','b',
   'c','d','e','f','g','h',
   'i','j','k','l','m','n',
   'o','p','q','r','s','t',
   'u','v','w','x','y','z',
   'A','B','C','D','E','F',
   'G','H','I','J','K','L',
   'M','N','O','P','Q','R',
   'S','T','U','V','W','X',
   'Y','Z','-','_','.','@',
   '?','?','?','?','?','?','?',
   '?','?','?','?','?','?','?',
   '?','?','?','?','?','?','?',
   '?','?','ネ','?','?','?','?',
   '?','?','?','?','ム','?','?',
   '?','?','?','?','?','?','?',
   '?','?','?'
 );
//全角数组
 $full = array(
   '0','1','2','3','4','5',
   '6','7','8','9','a','b',
   'c','d','e','f','g','h',
   'i','j','k','l','m','n',
   'o','p','q','r','s','t',
   'u','v','w','x','y','z',
   'A','B','C','D','E','F',
   'G','H','I','J','K','L',
   'M','N','O','P','Q','R',
   'S','T','U','V','W','X',
   'Y','Z','-','_','.','@',
   'ア','イ','ウ','エ','オ','カ','キ',
   'ク','ケ','コ','サ','シ','ス','セ',
   'ソ','タ','チ','ツ','テ','ト','ナ',
   'ニ','ヌ','ネ','ノ','ハ','ヒ','フ',
   'ヘ','ホ','マ','ミ','ム','メ','モ',
   'ヤ','イ','ユ','エ','ヨ','ラ','リ',
   'ル','レ','ロ',
 );
  var_dump(str_replace($half, $full, '???')); // 半角转全角
  var_dump(str_replace($full,$half,'テスト')); // 全角转半角

以上就介绍了php 中全半角转换,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn