Home >Backend Development >PHP Tutorial >Full and half-width conversion in php

Full and half-width conversion in php

WBOY
WBOYOriginal
2016-07-30 13:29:26913browse
// 半角数组 
$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,'テスト')); // 全角转半角

The above introduces the full-width and half-width conversion in PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Previous article:php learning 2Next article:php learning 2