DedeCMS织梦

织梦DedeCMS自动转换数字函数代码

阿里云

这个需求是余斗在织梦官方群里看到一个群友提出的,要实现网站中的数字自动转换为 X 千、X 万 X 千这样的表现形式。这个想法很独特,不过也很实用,特别对于那些频繁展现数字的网站来说。其实实现起来很简单,只需要在 include\extend.func.php 加个函数 即可。

具体代码:

  1.      function click_round_number( $number, $min_value = 1000, $decimal = 1 ) {
  2.  
  3.                 if( $number < $min_value ) {
  4.  
  5.                         return $number;
  6.  
  7.                 }
  8.  
  9.                 $alphabets = array( 100000000 => '亿', 10000 => '万', 1000 => '千' );
  10.  
  11.                 foreach( $alphabets as $key => $value )
  12.  
  13.             if( $number >= $key ) {
  14.  
  15.                 return round( $number / $key, $decimal ) . '' . $value;
  16.  
  17.             }
  18.  
  19.         }
也想出现在这里?联系我们
创客主机

调用方式:

  1. {dede:field.click function=click_round_number(@me)/} //以调用点击数字为例

实现效果为:1 万 3 千 4 百 2 十 5

织梦 DedeCMS 自动转换数字函数代码

已有 333 人购买
查看演示升级 VIP立刻购买

收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!