PHP Full-width half-width conversion

Source: Internet
Author: User


<?php
Header ("content-type:text/html; Charset=utf-8 ");
First argument: Passing in the string to be converted
Second parameter: Take 0, half angle turn full angle, take 1, full angle to half angle
function Sbc_dbc ($STR, $args 2) {
$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 (//Half Corner
' 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 ($args 2 = = 0) {
Return Str_replace ($SBC, $DBC, $STR); Half angle to full angle
} else if ($args 2 = = 1) {
Return Str_replace ($DBC, $SBC, $STR); Full angle to half angle
} else {
return false;
}
}


$str 1 = "fxc516";
$str 2 = "fxc516";
echo "Half angle turn full angle: <br/>";
echo $str 1. ' and '. SBC_DBC ($str 1, 0);

echo "<br/><br/> Full angle turning half angle: <br/>";
Echo $str 2. ' and '. Sbc_dbc ($str 2, 1);


?>

PHP Full-width half-width conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.