数据库中存储的金额是阿拉伯数字,但在产品需求中,需要将英文金额呈现给用户的消费单,所以调用该封装函数将阿拉伯数字金额转换为英文金额。1){$commas=$commas-1;}$words=implode(',',$words);//SomeFinishingTouch//用一个空格替换多个空格$words=trim(str_replace(',',',',trim_all(ucwords($words)),',');if($commas){$words=str_replace_last(',','and',$words);}返回$words;}elseif(!((int)$num)){返回'零';}return'';}functiontrim_all($str,$what=NULL,$with=''){if($what===NULL){//字符十进制使用//"\0"0空字符//"\t"9制表符//"\n"10新行//"\x0B"11垂直制表符//"\r"13Mac中的新行//""32空格$what="\\x00-\\x20";//所有空白和控制字符}returntrim(preg_replace("/[".$what."]+/",$with,$str),$what);}functionstr_replace_last($search,$replace,$str){if(($pos=strrpos($str,$search))!==false){$search_length=strlen($search);$str=substr_replace($str,$replace,$pos,$search_length);}返回$str;}
