9three Posted February 17, 2009 Share Posted February 17, 2009 Hey, <?php $gold = file_get_contents('http://www.site.com/'); preg_match_all('~<td class="td" align="Right">(.+?)</td>~is', $gold, $goldMatch); foreach ($goldMatch[0] as $gMatched) echo $gMatched[2].'<br>'; ?> When I run this code there are about 8 matches that come up. Out of those 8 I only need 3. So I tried to change it to echo $gMatched[2]; But all it outputted was a string 'd'. How can I only use what I need? I need [2], [5], and [7]. Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/ Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 umm try adding PREG_SET_ORDER preg_match_all('~<td class="td" align="Right">(.+?)</td>~is', $gold, $goldMatch, PREG_SET_ORDER); I am not a pro of preg_match_all but i think it's required for [0] ... Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/#findComment-764449 Share on other sites More sharing options...
sasa Posted February 17, 2009 Share Posted February 17, 2009 echo $goldMatch[0][2], ' - ', $goldMatch[0][5], ' - ', $goldMatch[0][7]; Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/#findComment-764453 Share on other sites More sharing options...
9three Posted February 17, 2009 Author Share Posted February 17, 2009 thanks that worked well sasa. I got a problem though, its out putting it 7 times. I don't know why it would do it 7 times as there are 8 matches in total. Either way it should display only once :/ 968.00 968.00 968.00 968.00 968.00 968.00 968.00 updated file: <?php $gold = file_get_contents('http://www.site.com/'); preg_match_all('~<td class="td" align="Right">(.+?)</td>~is', $gold, $goldMatch); foreach ($goldMatch[0] as $gMatched) echo $goldMatch[0][1].'<br>'; ?> Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/#findComment-764458 Share on other sites More sharing options...
9three Posted February 17, 2009 Author Share Posted February 17, 2009 Oh nevermind, I found the problem. I actually didn't need the loop. That was causing the irritations (duh). Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/#findComment-764463 Share on other sites More sharing options...
sasa Posted February 17, 2009 Share Posted February 17, 2009 Link to comment https://forums.phpfreaks.com/topic/145608-solved-unable-to-pull-proper-information/#findComment-764522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.