/
php-example.php
executable file
·49 lines (39 loc) · 1.26 KB
/
php-example.php
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
<?
/*
You may want to use oEmbed discovery instead of hard-coding the oEmbed endpoint.
*/
$oembed_endpoint = 'http://vimeo.com/api/oembed';
// Grab the video url from the url, or use default
$video_url = ($_GET['url']) ? $_GET['url'] : 'http://vimeo.com/7100569';
// Create the URLs
$json_url = $oembed_endpoint . '.json?url=' . rawurlencode($video_url) . '&width=640';
$xml_url = $oembed_endpoint . '.xml?url=' . rawurlencode($video_url) . '&width=640';
// Curl helper function
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
// Load in the oEmbed XML
$oembed = simplexml_load_string(curl_get($xml_url));
/*
An alternate approach would be to load JSON,
then use json_decode() to turn it into an array.
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vimeo PHP oEmbed Example</title>
</head>
<body>
<h1><?php echo $oembed->title ?></h1>
<h2>by <a href="<?php echo $oembed->author_url ?>"><?php echo $oembed->author_name ?></a></h2>
<?php echo html_entity_decode($oembed->html) ?>
</body>
</html>