Slowly, but surely, I'm assembling a website for personal usage where I search for the name of a movie and it returns me the metacritic rating of it. Here's what I got so far:
$web = file_get_contents("http://www.metacritic.com/movie/the-lion-king");
preg_match(
'/<span class="score_value" property="v:average">(.*?)<\/span>/s',
$web,
$match
);
foreach ($match as $score) {
$sc = $score;
echo $sc;
}
Result:
8383
Where it should return only 83 and not 8383.
I pointed the way to where the metacritic rating is located because I need to grab that information. I'm not sure whether or not it's correct? May be some very crude work, I don't understand preg_match very well, the documentation online did not help a bit.
Can someone please help me?
You should only echo out $score[1]
because that is where your first captured parenthesized subpattern will go.
Read documentation for preg_match
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With