[Solved] How do I parse “N/A – -0.09%” and extract the number after the first hyphen in PHP? [closed]


I wouldn’t use a regex here, I’d just remove the two quotes (replacing " with nothing using str_replace()), then split the string into words (using explode() with ‘ ‘ as the delimiter), then grab the last “word” using array_pop().

url="abc123.php";    
$data = file_get_contents($url);  //$data contains "N/A - -0.09%" (the string to parse)

$match = array_pop(explode(' ', str_replace("\"", '', $data)));
echo $match . "\n";

5

solved How do I parse “N/A – -0.09%” and extract the number after the first hyphen in PHP? [closed]