Skip to main content
3 of 4
added 3 characters in body
Brett
  • 165
  • 1
  • 6

Match all youtube links in a string of text

I'm looking to pull all the youtube links from a string of text and was wondering how does this look?

if (preg_match_all('/(https?:\/\/)?(www\.)?(youtube\.com)\/watch\?v=([a-zA-Z0-9_-]+)[^\s]*/im', $this->content, $matches)) {
    
}

Obviously this doesn't take into account the youtu.be links as they are formatted differently.

Brett
  • 165
  • 1
  • 6