Download the PHP package planetbiru/forex without Composer
On this page you can find all versions of the php package planetbiru/forex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package forex
Forex
Foreign Exchange
A PHP library to fetch and parse currency exchange rates from the European Central Bank (ECB). This library provides methods to convert currencies based on the retrieved exchange rates.
Important Performance Note
Fetching historical data (especially via loadHistory or loadByDate) involves processing large XML datasets. This operation should only be performed by back-end processes (e.g., cron jobs, background workers) and must not be triggered synchronously by front-end user actions. To ensure optimal performance, always prefer fetching the minimal dataset required (e.g., loadDaily or loadLast90Days) over the full history.
Table of Contents
- Installation
- Initialization
-
Loading Data
- loadDaily
- loadLast90Days
- loadHistory
- loadByDate
- load
-
Data Access & Manipulation
- get
- set
- convert
- getAllRates
- getDate
Installation
Install the library using Composer:
Initialization
Ensure that the class file is included or that an autoloader is being used.
Loading Data
loadDaily
Loads the latest daily reference exchange rates.
Example 1: Basic usage
Example 2: Reload daily data
Example 3: Check currency availability after loading
loadLast90Days
Loads exchange rate references from the last 90 days file (using the most recent date available in that file).
Example 1: Basic usage
Example 2: Using class constants
Example 3: Validation after loading
loadHistory
Loads exchange rate references from the full historical file (since 1999). By default, it retrieves the most recent available date.
Example 1: Basic usage
Example 2: Preparation for loadByDate
Example 3: Handling large files
loadByDate
Loads exchange rates for a specific date (YYYY-MM-DD) from the full historical dataset.
Example 1: Load a valid date
Example 2: Handle a date that is not found
Example 3: Searching dates in a loop
load
Loads data from a custom XML URL.
Example 1: Load from a custom URL
Example 2: Load from a local file
Example 3: Reload with a different source
Data Access & Manipulation
get
Retrieves the exchange rate for a specific currency.
Example 1: Get USD rate
Example 2: Get IDR (Indonesian Rupiah) rate
Example 3: Case insensitive
set
Manually sets an exchange rate.
Example 1: Override an existing rate
Example 2: Add a new currency
Example 3: Update IDR rate
convert
Converts an amount from one currency to another.
Example 1: Convert USD to IDR
Example 2: Convert EUR to GBP
Example 3: Convert JPY to USD
getAllRates
Returns all available exchange rates as an array.
Example 1: Dump all data
Example 2: Count available currencies
Example 3: Loop through all rates
getDate
Retrieves the date of the currently loaded exchange rate data.
Example 1: Display the date
Example 2: Format the date
Example 3: Date validation