PHP how to get the second number present in a string -



second number present in string. maybe have better ideas mine.

from example:

1 pln = 0.07 gold 

i "0.07" string. obtain web scraping returns me string.

the problem have following. "second number in string" might ".", without it, might composed 1 number ex. "1", or 2 "12", might have decimals ex. "1.2", position may change, because currency have "1 pln", "1 usd" others have "1 tw".

so can't work on position, can't extract numbers (i have "1" @ beginning of string), can't extract int cause have decimals...

so constant of string - think (but if have better ideas pls suggest me) - need second number find in string.

how it? sorry if wasn't enough clear.

try this:

<?php $string = '1 pln = 0.07 gold'; $pattern = '/\d+\.\d+/';  $matches = array(); $r = preg_match($pattern, $string, $matches);  var_dump($matches); //$matches array results 

output:

array(1) {   [0]=>   string(4) "0.07" } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -