Solution: Formatter and Hash Generation with Updated Functions
Explore practical solutions for handling PHP 8's updated NumberFormatter class to format currencies across various locales. Learn to build a versatile calculator function and implement a hash generator class for md5 and sha256. Understand how to adapt code for deprecated or removed functionalities to maintain performance and compatibility.
We'll cover the following...
Solution to Task 1
This challenge asked you to create a PHP script that demonstrates the use of the NumberFormatter class to format a monetary amount in different locales. You were provided with a code snippet that set the monetary locale to Japan, Germany, France, and the United Kingdom and formatted a given monetary amount accordingly.
Let’s get into the code.
Generating code for Japanese currency JPY:
Line 5: Create a variable
$fmtand set the monetary locale to Japanese currency JPY.Line 6: Display the currency in a national format using
$fmt->formatCurrency()method.Line 7: Generate a symbol for Japanese currency.
Line 8: Display the currency in an international format using the
$fmt->format()method.
Generating code for German currency EUR:
Line 11: ...