Home > Backend Development > PHP Tutorial > An example of code for converting php full-width numbers to half-width numbers

An example of code for converting php full-width numbers to half-width numbers

WBOY
Release: 2016-07-25 09:00:57
Original
951 people have browsed it
The PHP code implements converting chamfered numbers into half-width numbers. Friends in need can refer to it.

Many PHP tutorials on the Internet have such examples, but they are not as good as those in Programmer’s Home, haha, no nonsense, let’s take a look at the examples. Example:

<?php
//全角数字转半角数字
//by bbs.it-home.org
function GetAlabNum($fnum){
$nums = array('0','1','2','3','4','5','6','7','8','9','.','-','+',':');
$fnums = array('0','1', '2','3', '4','5', '6', '7','8', '9','.', '-', '+',':');
$fnlen = count($fnums);
for($i=0;$i<$fnlen;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);
$slen = strlen($fnum);
$oknum = '';
for($i=0;$i<$slen;$i++){
if(ord($fnum[$i]) > 0x80) $i++;
else $oknum .= $fnum[$i];
}
if($oknum=="") $oknum=0;
return $oknum;
}
?>
Copy after login


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template