Search code examples
phpfloating-pointtext-extraction

Extract float value from a string containing numbers, letters, and symbols


I want to get the value 146273.0017 from the following string.

(["JPY-XAU,146273.0017"]);

What is the best way to do this?


Solution

  • You can use a regex

    $str = '(["JPY-XAU,146273.0017"]);';
    
    preg_match("/,(.*?)\"/", $str, $res);
    
    echo $res[1]; // 146273.0017