конечные нули с функцией запятой, используя php

Привет, у меня код в javascript, который работает отлично, но такая же функциональность, которую я хочу на языке php. Я нахожу разные источники в Интернете, но не получаю успехов.

Код Javascript:

Number.prototype.formatMoney = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d ? "." : d, t = t ? "," : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; function trailingZerosWithComma() { var costAmount = $("#costAmount").val(); if(costAmount != "") { var costAmountReplace = parseFloat(costAmount.replace(/\,/g,'')); $("#costAmount").val((costAmountReplace).formatMoney(2, '.', ',')); } } <input type="text" name="costAmount" id="costAmount" onblur="trailingZerosWithComma();"> 

Но мне это нужно в php

 Number.prototype.formatMoney = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d ? "." : d, t = t ? "," : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; var costAmountReplace = parseFloat(costAmount.replace(/\,/g,'')); 

Solutions Collecting From Web of "конечные нули с функцией запятой, используя php"