Current Location: Home> Latest Articles> How to Replace or Solve the Issue of the Deprecated money_format Function in PHP 7 and Above

How to Replace or Solve the Issue of the Deprecated money_format Function in PHP 7 and Above

gitbox 2025-09-12
<span><span><span class="hljs-meta"><?php</span></span><span>  
</span><span><span class="hljs-comment">// This part of the code is unrelated to the article content and serves only as an example header code</span></span><span>  
</span><span><span class="hljs-title function_ invoke__">date_default_timezone_set</span></span><span>(</span><span><span class="hljs-string">&#039;Asia/Shanghai&#039;</span></span><span>);  
</span><span><span class="hljs-keyword">echo</span></span><span> </span><span><span class="hljs-string">"Current time: "</span></span><span> . </span><span><span class="hljs-title function_ invoke__">date</span></span><span>(</span><span><span class="hljs-string">&#039;Y-m-d H:i:s&#039;</span></span><span>);  
</span><span><span class="hljs-meta">?></span></span><span>  
<p><hr></p>
<p><h2>How to Replace or Solve the Issue of the Deprecated money_format Function in PHP 7 and Above</h2></p>
<p><p>In PHP 7.4 and later versions, the <code>money_format

In this example, NumberFormatter not only formats the number but also automatically adds the currency symbol, thousands separators, and decimal points based on the locale. Developers just need to specify the appropriate locale and currency code.

3. Benefits of Using NumberFormatter

  • Cross-platform: It is independent of the operating system's locale settings, ensuring consistent formatting across different platforms.
  • Multi-language and Multi-currency Support: Easily supports multiple countries and currency formats, making it ideal for international projects.
  • Feature-rich: Allows control over decimal places, symbol placement, and more, providing high flexibility.

4. Considerations

Before using NumberFormatter, make sure that the PHP environment has the intl extension enabled, otherwise an error will occur. Most modern PHP environments include this extension by default, but lightweight environments may require manual installation and configuration.

5. Conclusion

As PHP evolves, the money_format() function has been deprecated and should no longer be used. NumberFormatter is the recommended alternative, offering a more stable and cross-platform solution for formatting currencies. It is advised that all new projects and projects under maintenance migrate to NumberFormatter as soon as possible to ensure modern and compatible code.