sphinx Posted August 29, 2012 Share Posted August 29, 2012 Hello, I basically host a radio and want to preg_match the important information onto another website. Up until now, I file_get_contents like 4 times and preg_matched but required the site to be grabbed like 5 times before it even loaded. The information I want is something like this: I tested something like this: <?php $page_contents = file_get_contents("http://sitewherethepageaboveislocated.co.uk"); $matches = array(); preg_match('/([0-9]+) of 50/', $page_contents, $matches); //current listeners preg_match('~Kadio :.*?)</b>~i',$page_contents, $matches2); //what DJ is playing echo $matches[0]; echo $matches2[0]; ?> But it seems to be overly complicated when trying to preg_match loads of factors, is this the only way to do it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/267767-preg-matching-multiple-things-on-1-webpage/ Share on other sites More sharing options...
requinix Posted August 29, 2012 Share Posted August 29, 2012 Depending on the page there could be easier ways of doing it. If it's well-formed HTML then you can read it through DOMDocument. For instance, with Server Status: Server is currently up and private you could do a getElementById("server-status") to get that TD node. More complicated would be a getElementsByTagName, and worse would be manually traversing the hierarchy (ie, through childNodes and such). But IMO all three are preferable to regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/267767-preg-matching-multiple-things-on-1-webpage/#findComment-1373657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.