php - Regex, preg match -


ok, want read table website(exchange rate) i'm trying read data following lines:

<table width="100%" border="0"  

i copy of above lines , following lines can read data want address placed copy of table.

$content = file_get_contents("http://www.example.com/");  preg_match('#">([0-9,.]*)<.*">([0-9,.]*)<#uis', $content, $usdmatch); preg_match('#">([0-9,.]*)<.*">([0-9,.]*)<#uis', $content, $eurmatch); preg_match('#">([0-9,.]*)<.*">([0-9,.]*)<#uis', $content, $gbpmatch);  $eur = $eurmatch[2]; $usd = $usdmatch[2]; $gbp = $gbpmatch[2];  echo "eur: $eur usd: $usd gbp: $gbp"; 

but same lines, can't read table source! please advice me find mistake?

thanks

from more exchange turns out detail of redundant specifications caused mismatch.

tray following replacement. work:

preg_match('#monetarycode">usd.*monetarybuy">([0-9,.]*)<.*monetarysell">([0-9,.]*)<#uis', $content, $usdmatch); preg_match('#monetarycode">eur.*monetarybuy">([0-9,.]*)<.*monetarysell">([0-9,.]*)<#uis', $content, $eurmatch); preg_match('#monetarycode">gbp.*monetarybuy">([0-9,.]*)<.*monetarysell">([0-9,.]*)<#uis', $content, $gbpmatch);  $eur = $eurmatch[2]; $usd = $usdmatch[2]; $gbp = $gbpmatch[2]; 

i shortened regexp , eliminated unnecessary groupings. remarks greedyness , linebreaks have been illguided. had proper modifiers thatt overlooked in long rexep pattern strings. sorry confusion.


Comments