包含标签 php articles

PHP保留两位小数四舍五入

/** 1.number_format */ $number = 1234.5678; $nombre_format_francais = number_format($number, 2, ',', ' '); // 1234,57 $english_format_number = number_format($number, 2, '.', ''); // 1234.57(我一般用这个) /** 2.round */ $number = 1234.5678; echo round($number ,2); //1234.57 /** 3.sprintf */ $formatted = sprintf ("%s有¥%01.2f。", $name, $money); echo $formatted; //张三有¥123.10。……

Continue reading

PHP字符串关键字过滤

/** * 字符串关键字过滤 * @param $find 要查找的值 * @param $replace 替换 find 中的值的值 * @param $subject 被搜索的字符串 * @return bool|mixed 返回替换后的字符串 */ public function keyword_replace($find, $replace, $subject) { if(is_array($find) && !empty($find)){ $subject = str_replace(' ', '',$subject); //过滤空格 foreach($find as $v){ $len = mb_strlen($v, 'utf-8'); $x = ''; for($i = 0; $i < $len; $i++){ $x .= $replace; } $str2 = str_replace($v, $x, $subject); $subject =……

Continue reading