-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathvideo_helper.php
More file actions
51 lines (46 loc) · 1.55 KB
/
video_helper.php
File metadata and controls
51 lines (46 loc) · 1.55 KB
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
<?php
/**
* embedVideo ()
* -----------------------------------------------------------------------
*
* This method will allow you to embed any youtube video by just passing
* it the youtube embed code example: RLyXR8Pk-GY
* By just using the youtube code we can store the codes in a database.
*
* Usage:
*
* Copy the code from the url bar on youtube and paste it like below.
* https://www.youtube.com/watch?v=RLyXR8Pk-GY
* | copy |
* $data = ['video' => embedVideo('RLyXR8Pk-GY'),];
* echo view('your_view', $data);
*
* You can setup more data[] video variables that you need.
*/
if (! function_exists('embedVideo')) {
/**
* embedVideo ()
* -------------------------------------------------------------------
*
* @return false|string
*/
function embedVideo(string $code, string $width = '640', string $height = '385')
{
$code = trim($code);
// Parse URL's to find the code
$url = filter_var($code, FILTER_VALIDATE_URL);
if (! empty($url)) {
parse_str(substr($url, strpos($url, '?') + 1), $result);
$code = $result['v'] ?? null;
}
if (! in_array($code, ['', null, '0', []], true)) {
return '
<iframe width="' . $width . '" height="' . $height . '"
src="https://www.youtube.com/embed/' . $code . '" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media;
gyroscope; picture-in-picture" allowfullscreen>
</iframe>';
}
return false;
}
}