markus-g/price-parser

解析价格或货币字符串

0.1.1 2016-03-12 00:58 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:24:42 UTC


README

PHP 5.3+ 库,用于解析价格或货币字符串并获取其货币和金额!

<?php
use PriceParser\Price;

$priceWithCurrency = '12,499,50 €';
$price = new Price($priceWithCurrency);

//float value e.g. 15.20
$price->getAmount();

//currency symbol, e.g. $ or €
$price->getCurrencySymbol();

//currency iso code, e.g. EUR or USD
$price->getCurrencyIsoCode();

//currency name, e.g. Euro or US Dollar
$price->getCurrencyName();

//the raw value, e.g. 12,499,50 €
$price->getValue();

//price is valid if a currency can be found and amount is not empty or null
$price->isValid();

安装

使用 composer 安装库。将以下内容添加到您的 composer.json

{
    "require": {
        "markus-g/price-parser": "0.1.*"
    }
}

现在运行 install 命令。

$ composer.phar install