timmah1 Posted February 17, 2009 Share Posted February 17, 2009 I'm trying to find a tutorial or something that will allow me to show movie times from Fandango on my site. I found one thing, but it's not displaying anything. <? $url = "http://www.fandango.com/san+diego_ca_movietheatershowtimes"; $file = "content.inc"; $unique_start = '<table width="677" border="0" cellspacing="0" cellpadding="0">'; $unique_end = '<table width="678" border="0" cellspacing="0" cellpadding="0">'; ini_set('max_execution_time', '0'); flush (); // fetch domain from url $fetch_domain = parse_url($url); $fetch_domain = $fetch_domain[host]; // Host checking code $socket_handle = fsockopen("$fetch_domain", 80, $error_nr, $error_txt,30); if(!$socket_handle) { print("Cannot make a connection to: $fetch_domain and therefore cannot collect your requested data"); $contents = implode("",@file( $file ) ); echo $contents; exit; } $fd= fread(fopen("$url", "r"), 100000); if ($fd) { $start= strpos($fd, "$unique_start"); $finish= strpos($fd, "$unique_end"); $length= $finish-$start; $code=substr($fd, $start, $length); } echo $code; $tmpfile = fopen($file,"w+"); $fp = fwrite($tmpfile,$code); fclose($tmpfile); flush (); ?> Does anybody know how I could modify this script, or a good tutorial to show how this can be done? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/145503-grab-content/ Share on other sites More sharing options...
MadTechie Posted February 17, 2009 Share Posted February 17, 2009 OKay this is just a basic idea.. but should help.. your need to tweak the RegEx (we have a RegEx section) <?php $html = file_get_contents("http://www.fandango.com/san+diego_ca_movietheatershowtimes"); preg_match_all('%<div class="title">.*?<h4>.*?<a[^>]*?>\s*(.*?)</a>.*?</h4>.*?</div>.*?<div\s+class="times">(.*?)</div>%sim', $html, $result, PREG_PATTERN_ORDER); $result = $result[0]; foreach($result as $r) { echo $r; } ?> Please note the RegEx was written in a kinda rush.. so some clean up is required Quote Link to comment https://forums.phpfreaks.com/topic/145503-grab-content/#findComment-763956 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.