Martijn thank you for the awesome response. I appreciate all your help. I took it a step further and added dailymotion also. I rarely see vimeo videos posted on message boards. If it is requested later on down the road I may add it, and may even have to refer back to this excellent response.
Thank you so much for your help!
% foreach ($template->query('//article/div/p[a and count(*)=1 and not(normalize-space(text()))]') as $node) { $link = trim($node->nodeValue); $replace = false; if ( preg_match('~(?: https?://(?:www\.)?youtu(?:be\.com/(?:embed/|watch\?(?:.+&)?v=)|\.be/)([a-z0-9_\-]+) # Parsing YouTube URLs. | (.+\.(?:png|jpe?g|gif)) # Parsing image URLs. | https?://(?:www\.)?liveleak.com/ll_embed\?f=([a-z0-9]+) # Parsing LiveLeak embed URLs. | https?://(?:www\.)?dailymotion.com/embed/video/([a-z0-9]+) # Parsing Dailymotion URLs. )~ixA', $link, $matches) ) { if (strlen($matches[1])) { // We found a YouTube video. $replace = '<iframe src="https://www.youtube-nocookie.com/embed/' . $matches[1] . '?autoplay=0&rel=0" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>'; } else if (strlen($matches[2])) { // We found an image link. $replace = '<a href="' . safeHTML($link) . '"><img src="' . $matches[2] . '" alt="' . safeHTML($link) . '" /></a>'; } else if (strlen($matches[3])) { // We found a LiveLeak video. $replace = '<iframe width="640" height="360" src="https://www.liveleak.com/ll_embed?f=' . $matches[3] . '" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>'; } else if (strlen($matches[4])) { // We found a Dailymotion video. $replace = '<iframe width="640" height="360" src="https://www.dailymotion.com/embed/video/' . $matches[4] . '" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>'; } } if ($replace) { $frag = $node->ownerDocument->createDocumentFragment(); if (!@$frag->appendXML($replace) || !@$node->parentNode->replaceChild($frag, $node)) { throw new Exception("Invalid HTML"); } } } } %