I want to get the id of the youtube video i used this code :
$url = $video->link;
if (preg_match('/youtube\.com\/watch\?v=([^\&\?\/]+)/', $url, $videoId)) {
$values = $videoId[1];
} else if (preg_match('/youtube\.com\/embed\/([^\&\?\/]+)/', $url, $videoId)) {
$values = $videoId[1];
} else if (preg_match('/youtube\.com\/v\/([^\&\?\/]+)/', $url, $videoId)) {
$values = $videoId[1];
} else if (preg_match('/youtu\.be\/([^\&\?\/]+)/', $url, $videoId)) {
$values = $videoId[1];
}
else if (preg_match('/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/', $url, $id)) {
$values = $videoId[1];
} else {
// not an youtube video
}
I get this error "htmlspecialchars() expects parameter 1 to be string, array given" . the error is that this code give me an array when i want a string is there a solution to get the id of the youtube video in a string format ?