Specifically convert only YouTube urls to iframe tags while converting BBCode urls to html elements
问题 I'm trying to convert youtube video links into iframes to embed them onto my website but I'm having a problem as I am already converting urls to anchor tags and it's conflicting with the youtube url. Here is my code: $string = 'https://www.google.com and https://www.youtube.com/watch?v=umFQckeDwEE'; $url = '~(\s|^)(https?://.+?)(\s|$)~im'; $string = preg_replace($url, '[url=$0]$0[/url]', $string); $youtubeURL = '/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\