PHP自定义函数:全角半角实现互转_PHP教程
时间:2021-07-01 10:21:17
帮助过:11人阅读
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);
?>
http://www.bkjia.com/PHPjc/486070.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486070.htmlTechArticle?PHP function SBC_DBC($str,$args2) { //半角和全角转换函数,第二个参数如果是0,则是半角到全角;如果是1,则是全角到半角 $DBC = array( 0 , 1 , 2...