Jnerocorp Posted April 1, 2010 Share Posted April 1, 2010 Hello, I would like to use PHP to capture any text between tags so what I want to do is Get the text between: <tbody> <tr class=""> <td width="153"> <img alt="live_" src="/global/support/PublishingImages/global/live_.png"></td> <td class="last"><p>Service is up and running.</p></td> </tr> <tr><td width="153"><img alt="marketplace_" src="/global/support/PublishingImages/global/marketplace_.png"></td> <td class="last"><p>Service is up and running.</p></td> </tr><tr><td width="153"><img alt="account_" src="/global/support/PublishingImages/global/account_.png"></td> <td class="last"><p>Service is up and running.</p></td> </tr><tr><td width="153"><img alt="matchmaking_" src="/global/support/PublishingImages/global/matchmaking_.png"></td> <td class="last"><p>Service is up and running.</p></td> </tr> </tbody> so what I want is everything between "<td class="last"><p>" and "</p></td>" as you can see it shows up so i dont know if its possible to get them as a variable like this: $match[0] $match[1] $match[2] $match[3] it is from another url from another site so it would have to read it from another url and retrieve the conents does anyone know if this is possible? -John Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/ Share on other sites More sharing options...
MadTechie Posted April 1, 2010 Share Posted April 1, 2010 untested but this should work $html = "HTML CODE HERE"; preg_match_all('%<td class="last"><p>(.*?)</p></td>%', $html, $match, PREG_PATTERN_ORDER); $match = $match[1]; foreach($match as $matches){ echo $matches; } Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035024 Share on other sites More sharing options...
Jnerocorp Posted April 1, 2010 Author Share Posted April 1, 2010 didnt work i tried it like this: <?php $html = "WEBSITE URL HERE"; preg_match_all('%<td class="last"><p>(.*?)</p></td>%', $html, $match, PREG_PATTERN_ORDER); $match = $match[1]; foreach($match as $matches){ echo $matches; } ?> and it does nothing Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035025 Share on other sites More sharing options...
teamatomic Posted April 1, 2010 Share Posted April 1, 2010 $file=file_get_contents("./test.txt"); preg_match('~\<td class="last"><p>(.+?)</p></td>~i',$file,$matches); $found=trim($matches[1]); echo "$found<P>"; echo "<pre>"; print_r($matches); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035029 Share on other sites More sharing options...
Jnerocorp Posted April 1, 2010 Author Share Posted April 1, 2010 @teamatomic I tried your code: <?php $file=file_get_contents("http://support.xbox.com/support/en/us/nxe/xboxstatus.aspx"); preg_match('~\<td class="last"><p>(.+?)</p></td>~i',$file,$matches); $found=trim($matches[1]); echo "$found<P>"; echo "<pre>"; print_r($matches); ?> and its returning this: Array ( ) Code is not working Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035032 Share on other sites More sharing options...
MadTechie Posted April 1, 2010 Share Posted April 1, 2010 Well the url your using doesn't have <td class="last"><p> in it so, you could say it is working.. try this $html = file_get_contents("http://support.xbox.com/support/en/us/nxe/xboxstatus.aspx"); preg_match_all('%</td><td><p>(.*?)</p></td></tr><tr>%', $html, $match, PREG_PATTERN_ORDER); $match = $match[1]; foreach($match as $matches){ echo "$matches<BR />\n"; } Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035033 Share on other sites More sharing options...
Jnerocorp Posted April 1, 2010 Author Share Posted April 1, 2010 well now its grabbing 3 of them but not all 4 and I cant control each one I need to be able to do it like this: echo "Xbox Live: ". $match[0] .""; echo "Xbox Live Marketplace: ". $match[1] .""; echo "Xbox Live Billing: ". $match[2] .""; echo "Xbox Live Match Making: ". $match[3] .""; sorry to be such a hassle but im still trying to understand this stuff Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035045 Share on other sites More sharing options...
MadTechie Posted April 1, 2010 Share Posted April 1, 2010 No worries remove the last <tr> so change preg_match_all('%</td><td><p>(.*?)</p></td></tr><tr>%', $html, $match, PREG_PATTERN_ORDER); to preg_match_all('%</td><td><p>(.*?)</p></td></tr>%', $html, $match, PREG_PATTERN_ORDER); Translation Find </td><td><p> then (.*?) capture everything until </p></td></tr> Link to comment https://forums.phpfreaks.com/topic/197182-php-find-text-from-another-page-between-tags/#findComment-1035053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.