I need a help in regex php. If in a string find number after some character. get that number and replace it with after applying math. Like currency convert.
I applied this regex https://regex101.com/r/KhoaKU/1
([^\?])AUD (\d)
regex not correct I want all matched number here only it's matched 40 but there also 20.00, 9.95 etc.. I am trying to get all. and convert them.
function simpleConvert($from,$to,$amount)
{
$content = file_get_contents('https://www.google.com/finance/converter?a='.$amount.'&from='.$from.'&to='.$to);
$doc = new DOMDocument;
@$doc->loadHTML($content);
$xpath = new DOMXpath($doc);
$result = $xpath->query('//*[@id="currency_converter_result"]/span')->item(0)->nodeValue;
return $result;
}
$pattern_new = '/([^\?]*)AUD (\d*)/';
if ( preg_match ($pattern_new, $content) )
{
$has_matches = preg_match($pattern_new, $content);
print_r($has_matches);
echo simpleConvert("AUD","USD",$has_matches);
}