Parse currency from string

前端 未结 5 1532
无人及你
无人及你 2021-01-02 18:25

I want to parse a currency from a string in PHP, I\'ve had a look at number formatter but haven\'t got PHP 5.3 or the ability to add extensions.

The currency will on

5条回答
  •  梦毁少年i
    2021-01-02 19:26

    preg_match('/(?<=£)(?=[\d.]*\d)(\d*(?:\.\d*)?)/', $input, $matches);
    

    will find a match within any of these:

    • £.10
    • £0.10
    • £100
    • £100.00

    etc.

提交回复
热议问题