Php converts fullwidth characters to halfwidth characters

Source: Internet
Author: User
Users often write full-width English characters or punctuation marks. Sometimes the system cannot recognize them. Therefore, convert all full-width characters into normal half-width characters to reduce the problem. In fact, the principle is very simple, it is also very stupid, that is, to replace all the full-width characters with the corresponding half-width characters, from the open source code of ecshop. *** Convert a string

Users often write full-width English characters or punctuation marks. Sometimes the system cannot recognize them. Therefore, convert all full-width characters into normal half-width characters to reduce the problem. In fact, the principle is very simple, it is also very stupid, that is, to replace all the full-width characters with the corresponding half-width characters, from the open source code of ecshop. /***

Users often write full-width English characters or punctuation marks. Sometimes the system cannot recognize them. Therefore, convert all full-width characters into normal half-width characters to reduce the problem. In fact, the principle is very simple, it is also very stupid, that is, to replace all the full-width characters with the corresponding half-width characters, from the open source code of ecshop.

/*** Enclose a string with full-width numbers, letters, spaces, or '% + -() 'character conversion to the corresponding halfwidth character ** @ access public * @ param string $ str string to be converted ** @ return string $ str processed string */function make_semiangle ($ str) {$ arr = array ('0' => '0', '1' => '1', '2' => '2 ', '3' => '3', '4' => '4', '5' => '5', '6' => '6 ', '7' => '7', '8' => '8', '9' => '9', 'A' => 'A ', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E ', 'F' => 'F', 'G' => 'G', 'H' => 'h', 'I' => 'I', 'J' => 'J', 'K' => 'k', 'L' => 'l', 'M' => 'M', 'n' => 'n ', 'o' => 'O', 'p' => 'P', 'q' => 'Q', 'R' => 'R ', 'S '=>'s', 't' => 'T', 'U' => 'U', 'V' => 'V ', 'W' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'Z ', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D ', 'E' => 'E', 'F' => 'F', 'G' => 'G', 'H' => 'h ', 'I' => 'I', 'J' => 'J', 'K' => 'k', 'L' => 'l ', 'M' => 'M', 'n' => 'n', 'O' => 'O', 'p' => 'P ', 'q' =>' Q', 'R' => 'R', 's' => 's', 't' => 'T', 'U' => 'U ', 'V' => 'V', 'w' => 'w', 'x' => 'x', 'y' => 'y ', 'Z' => 'Z', '(' => '(', ')' => ')', '[' => '[', ']' => ']', '[' => '[', ']' => ']', '<' => '[', '〗' => ']', '=>' [',' "'=>'] ', ''' => '[', ''' => ']', '{' => '{', '}' => '}', '=>' <', '"' => ',' % '=>' % ',' + '=>' + ','-'=> '-', '-' => '-','~ '=>'-',': '=> ':','. '=> '. ',', '=>', '=> '. ',', '=> '. ','; '=> ',','? '=> '? ','! '=> '! ','... '=>'-', ''' =>' | ',' "'=>'" ', ''' => ''', ''' => ''', '|' => '|', 'Region' => '"','' => ''); return strtr ($ str, $ arr );}

Original article address: php converts full-width characters into half-width characters. Thank you for sharing it with the original author.

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.