Extract floating point numbers from a string in PHP

前端 未结 5 1975
盖世英雄少女心
盖世英雄少女心 2020-12-02 00:22

I would like to convert a string into floating numbers. For example

152.15 x 12.34 x 11mm

into

152.15, 12.34 and 11
         


        
5条回答
  •  感动是毒
    2020-12-02 01:00

    $str = "152.15 x 12.34 x 11mm";
    $str = str_replace("mm", "", $str);
    $str = explode("x", $str);
    print_r($str); // Array ( [0] => 152.15 [1] => 12.34 [2] => 11 ) 
    

    Tested it and it works on all strings above.

提交回复
热议问题