You are here

protected function UrlToVideoFilterService::parseYouTubeUrls in URL to Video Filter 2.0.x

Same name and namespace in other branches
  1. 8 src/Service/UrlToVideoFilterService.php \Drupal\url_to_video_filter\Service\UrlToVideoFilterService::parseYouTubeUrls()

Parses text for YouTube URLs.

Parameters

string $text: The text to parse for YouTube URLs.

Return value

array An array containing any YouTube URLs found in the text

1 call to UrlToVideoFilterService::parseYouTubeUrls()
UrlToVideoFilterService::convertYouTubeUrls in src/Service/UrlToVideoFilterService.php
Converts URLs to embedded YouTube videos.

File

src/Service/UrlToVideoFilterService.php, line 63

Class

UrlToVideoFilterService
Service class for the URL To Video Filter module.

Namespace

Drupal\url_to_video_filter\Service

Code

protected function parseYouTubeUrls($text) {
  $urls = [];
  $youtube_regex = '/(^|\\b)http(s)?:\\/\\/(www\\.)?youtube\\.com\\/watch.+?(?=($|\\s|\\r|\\r\\n|\\n|<))/m';
  preg_match_all($youtube_regex, $text, $matches);
  $urls = array_merge($urls, $matches[0]);
  $youtube_regex = '/(^|\\b)http(s)?:\\/\\/(www\\.)?youtu\\.be\\/.+?(?=($|\\s|\\r|\\r\\n|\\n|<))/m';
  preg_match_all($youtube_regex, $text, $matches);
  $urls = array_merge($urls, $matches[0]);
  $youtube_regex = '/(^|\\b)http(s)?:\\/\\/(www\\.)?youtube\\.com\\/embed.+?(?=($|\\s|\\r|\\r\\n|\\n|<))/m';
  preg_match_all($youtube_regex, $text, $matches);
  $urls = array_merge($urls, $matches[0]);
  return $urls;
}