/
test.imdb.php.txt
83 lines (59 loc) · 1.87 KB
/
test.imdb.php.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Test script for class.imdb.php
* This script shows sample usage of the class.imdb.php (IMDB Grabber Script)
*
* How to use:
*
* $imdbObj = new Imdb();
* $movieInfo = $imdbObj->get('http://www.imdb.com/title/tt0367882/');
*
* $movieInfo should contain all the details of that movie in associative Array Format
*
* You can also grab based on a search string like:
* $movieInfo = $imdbObj->get('The Matrix');
*
* For Full Details, refer to:
* http://www.itsalif.info/content/imdb-details-grabber-using-php-dom-xpath-extract-movie-details
*
*
*/
include 'class.imdb.php';
// only showing error, i.e turning off warning as new imdb layout throws bunch of warnings
error_reporting(E_ERROR);
$imdbObj = new Imdb();
// a helper function to echo movie details
function echoMovieDetails(&$movieInfo) {
if($movieInfo != false) {
echo '<pre>';
print_r($movieInfo);
echo '</pre>';
} else {
echo '<pre>Invalid Search Term or Invalid Imdb URL. No such Movie exists on IMDB</pre>';
}
}
$path = 'http://www.imdb.com/title/tt0133093/'; // the Matrix Movie
$matrixInfo = $imdbObj->get($path);
echoMovieDetails($matrixInfo);
// movie: The Transformers (using a search query)
$path = 'Transformers';
// grabbing with cast
$movieInfo = $imdbObj
->showCast(true)
->get($path);
echoMovieDetails($movieInfo);
// An Invalid Search Parameter:
$path = 'x94589485';
// grabbing with cast
$movieInfo = $imdbObj
->showCast(true)
->get($path);
echoMovieDetails($movieInfo);
// grab with custom stuff, movie: Shutter Island
$path = 'Shutter Island';
$movieInfo = $imdbObj->add('Writers:', '/div/a')
->add('Genre:', '/div/a')
->showRating(true)
->get($path);
echoMovieDetails($movieInfo);
?>