Home > php教程 > php手册 > PHP自定义函数:全角半角实现互转

PHP自定义函数:全角半角实现互转

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:40:44
Original
1100 people have browsed it

function SBC_DBC($str,$args2) { //半角和全角转换函数,第二个参数如果是0,则是半角到全角;如果是1,则是全角到半角
    $DBC = 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 , - ,    , : ,
  . , , , / , % , # ,
  ! , @ , & , ( , ) ,
  < , > , " , ' , ? ,
  [ , ] , { , } , \ ,
  | , + , = , _ , ^ ,
  ¥ ,  ̄ , `
    );
  $SBC = 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, -, , :,
   ., ,, /, %, #,
   !, @, &, (, ),
   , ", ,?,
   [, ], {, }, \,
   |, , =, _, ^,
   $, ~, `
    );
if($args2==0)
   return str_replace($SBC,$DBC,$str);  //半角到全角
if($args2==1)
   return str_replace($DBC,$SBC,$str);  //全角到半角
else
   return false;
}

//函数调用
$str = "alskdf";
echo $str;
echo "
";
echo SBC_DBC($str,0);
echo SBC_DBC($str,1);
?>

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template