Working on a community website, converting it from ASP to PHP. At the moment, the client manually enters the movie times each week for our local theater, which they grab from another website. I figured I would try to automate this process since we are redoing the site anyway, so I found PHP Simple HTML DOM Parser. I'm stuck on selecting the rating of the movie (PG, 18, etc).
Here is a div that includes the information for one movie:
<div class="mshow">
<span style="float:right; font-size:11px;">
<a href="/trailers/enders-game/19330/" title="enders-game movie trailer" style="font-size:11px;">Trailer</a> |
<a href="/reviews/enders-game/30945/" title="Ender's Game movie reviews" style="font-size:11px;">Rating: </a>
<b>Tribute</b>
<img src="/images/stars/4_sm.gif" alt="Current rating: 3.88" border="0" />
</span>
<strong>
<a href="/movies/enders-game/30945/" title="Ender's Game movie info">Ender's Game</a>
</strong>
(PG)<br />
<div class="block"> </div>
<div class="rsd">Fri, Nov 15: </div>
<div class="rst" >7:00pm 9:20pm </div><br />
<div class="rsd">Sat, Nov 16: </div>
<div class="rst" >1:00pm 3:15pm 7:00pm 9:20pm </div><br />
<div class="rsd">Sun, Nov 17: </div>
<div class="rst" >1:00pm 3:15pm 7:00pm 9:20pm </div><br />
<div class="rsd">Mon, Nov 18: </div>
<div class="rst" >7:00pm 9:20pm </div><br />
<div class="rsd">Tue, Nov 19: </div>
<div class="rst" >7:00pm 9:20pm </div><br />
<div class="rsd">Wed, Nov 20: </div>
<div class="rst" >7:00pm 9:20pm </div><br />
<div class="rsd">Thu, Nov 21: </div>
<div class="rst" >7:00pm 9:20pm </div><br />
</div>
And here is my code so far:
<?php
include_once('../simple_html_dom.php');
$html = file_get_html('http://www.tribute.ca/showtimes/theatres/may-cinema-6/mayc5/?datefilter=-1');
$movies = array();
foreach ($html->find("div.mshow") as $movie) {
$item['trailer'] = $movie->find('a', 0)->href;
$item['reviews'] = $movie->find('a', 1)->href;
$item['link'] = $movie->find('a', 2)->href;
$item['title'] = $movie->find('a', 2)->plaintext;
$movies[] = $item;
}
var_dump($movies);
?>
I can't figure out how to grab (PG). Any suggestions?
Edit: This works, but doesn't seem like a great solution.
function parseDOM($url) {
$movies = array();
foreach ($url->find("div.mshow") as $movie) {
$item['trailer'] = $movie->find('a', 0)->href;
$item['reviews'] = $movie->find('a', 1)->href;
$item['link'] = $movie->find('a', 2)->href;
$item['title'] = $movie->find('a', 2)->plaintext;
$info = $movie->plaintext;
preg_match('/\((.*?)\)/', $info, $matches);
$item['rating'] = $matches[1];
$movies[] = $item;
}
return $movies;
}