This series of articles is to share with you some common and practical PHP functions. This article is the first one. Let’s do a simple , remove excess 0
The code is very concise and simple, so there won’t be much nonsense.
The code is as follows:
/**
* Remove excess 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;
}
Friends can do a lot of things with free expansion. I hope you all like it.