Home > Backend Development > PHP Tutorial > PHP实用函数分享之去除多余的0_PHP

PHP实用函数分享之去除多余的0_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-31 13:17:22
Original
1020 people have browsed it

代码很简洁,也很简单,就不多废话了。

代码如下:


/**
 * 去除多余的0
 */ 
function del0($s) 

    $s = trim(strval($s)); 
    if (preg_match('#^-?\d+?\.0+$#', $s)) { 
        return preg_replace('#^(-?\d+?)\.0+$#','$1',$s); 
    }  
    if (preg_match('#^-?\d+?\.[0-9]+?0+$#', $s)) { 
        return preg_replace('#^(-?\d+\.[0-9]+?)0+$#','$1',$s); 
    } 
    return $s; 
}

小伙伴们自由扩展下,可以做很多事情,希望大家能够喜欢。

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template