function youtube_get_video_id in YouTube Field 8
Same name and namespace in other branches
- 7 youtube.inc \youtube_get_video_id()
Extracts the video_id from the submitted field value.
Parameters
string $input: The input submitted to the field.
Return value
string|bool Returns the video_id if available, or FALSE if not.
2 calls to youtube_get_video_id()
- YouTubeDefaultWidget::validateInput in src/
Plugin/ Field/ FieldWidget/ YouTubeDefaultWidget.php - Validate video URL.
- YouTubeItem::prepareValue in src/
Feeds/ Target/ YouTubeItem.php - Prepares a single value.
File
- ./
youtube.module, line 43 - Youtube field module adds a field for YouTube videos.
Code
function youtube_get_video_id($input) {
// See README.txt for accepted URL formats.
preg_match("/^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\\/))([^\\?&\"'<> ]+)/", $input, $matches);
if (!empty($matches[1])) {
$video_id = $matches[1];
return $video_id;
}
return FALSE;
}