Answer the question
In order to leave comments, you need to log in
Need regular expression evaluation and criticism?
There are different types of links to YouTube channels:
http://www.youtube.com/user/TheJuicyJVEVO
https://www.youtube.com/channel/UC4SusBgD3b1G5cCh_gjA81g
http://www.youtube.com/user/fabrikaband?gl=RU&hl=ru
https://www.youtube.com/channel/UCd2R33j8_ZtNtP2HmXNqAGA/featured
https://www.youtube.com/channel/UCd2R33j8_ZtNtP2HmXNqAGA/videos?a=b&b=c
function getGetIdChannel($link)
{
preg_match('~(channel\/|user\/)(?P<unslash>[\w_-]+)|\/(channel\/|user\/)(?P<slash>[\w_-]+)\/~ui', $link, $matches);
if (isset($matches['unslash']) && !empty($matches['unslash'])) {
return $matches['unslash'];
} elseif (isset($matches['slash']) && !empty($matches['slash'])) {
return $matches['slash'];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question