search
Homephp教程php手册PHP数字转汉字的函数算法

PHP数字转汉字的函数算法

Jun 06, 2016 pm 07:52 PM
linuxphpfunctionnumberChinese characterCommunityalgorithmEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 PHP数字转汉字的函数 /*********************数字转汉字***********************/ function del0($num) //去掉数字段前面的0 { return "".intval($num); } function n2c($x) //单个数字变汉字

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  PHP数字转汉字的函数

  /*********************数字转汉字***********************/

  function del0($num) //去掉数字段前面的0

  {

  return "".intval($num);

  }

  function n2c($x) //单个数字变汉字

  {

  $arr_n = array("零","一","二","三","四","五","六","七","八","九","十");

  return $arr_n[$x];

  }

  function num_r($abcd) //读取数值(4位)

  {

  $arr= array();

  $str = ""; //读取后的汉字数值

  $flag = 0; //该位是否为零

  $flag_end = 1; //是否以"零"结尾

  $size_r = strlen($abcd);

  for($i=0; $i

  {

  $arr[$i] = $abcd{$i};

  }

  $arrlen = count($arr);

  for($j=0; $j

  {

  $ch = n2c($arr[$arrlen-1-$j]); //从后向前转汉字

  //echo $ch;

  //echo "
";

  if($ch == "零" && $flag == 0){ //如果是第一个零

  $flag = 1; //该位为零

  $str = $ch.$str; //加入汉字数值字符串

  continue;

  }elseif($ch == "零"){ //如果不是第一个零了

  continue;

  }

  $flag = 0; //该位不是零

  switch($j)  {

  case 0: $str = $ch;    $flag_end = 0; break; //第一位(末尾),没有以"零"结尾

  case 1: $str = $ch."十".$str; break; //第二位

  case 2: $str = $ch."百".$str; break; //第三位

  case 3: $str = $ch."千".$str; break; //第四位

  }

  }

  if($flag_end == 1) //如果以"零"结尾

  {

  mb_internal_encoding("UTF-8");

  $str = mb_substr($str, 0, mb_strlen($str)-1); //把"零"去掉

  }

  if($arrlen == 2 && $arr[0] == 1){

  $str = substr($str,2);

  }

  return $str;

  }

[1] [2] 

PHP数字转汉字的函数算法

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.