I am trying to replace youtube links including the a tags with the iframe embed code. What I got so far:
$tube_link = "<a href="http://www.youtube.com/watch?v=XA5Qf8VHh9I&feature=g-all-u&context=G2f50f6aFAAAAAAAADAA" target="_blank" rel="nofollow">http://www.youtube.com/watch?v=XA5Qf8VHh9I&feature=g-all-u&context=G2f50f6aFAAAAAAAADAA</a>"
$search = '%<a(.*)(?:href="https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v= ))([\w\-]{10,12})(?:)([\w\-]{0})\b%x';
$replace = '<iframe width="150" height="84" src="http://www.youtube-nocookie.com/embed/$2"></iframe>';
$embed_code = preg_replace($search, $replace, $tube_link);
Result:
<iframe src="http://www.youtube-nocookie.com/embed/XA5Qf8VHh9"></iframe>&feature=g-all-u&context=G2f50f6aFAAAAAAAADAA</a>
How can I get rid of the remaining:
&feature=g-all-u&context=G2f50f6aFAAAAAAAADAA</a>
Thnx!