Redrum333 Posted September 3, 2010 Share Posted September 3, 2010 Heya guys, it's another youtube question. I was searching around the forum but since im not skillful in php, perhaps i can't make the most of it as i've already tryed everything. I suppose this will defo hook me into regex & php now. I would like to embed youtube links inside SMF without using any mod, since i'm convinced it can be done with simple hacks in few lines of code. So the tag itself is: //youtube.embedder array( 'tag' => 'youtube', 'before' => '<embed src="http://www.youtube.com/v/', 'after' => '&&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="never" allowfullscreen="true" width="425" height="341"></embed>', ), .. which comes in arrays defining forum tags. With this alone, any type of posts like in format > [youtube]videoid[/youtube] work without a problem. Now the tricky part, i would like to preg_replace youtube url portion of the post with videoid inside predefined tag. Closest i got is with the following examples, and i added problems they have: 1) This doesn't strip whatever comes after the videoid (e.g. '&feature=related' if in url) $message = preg_replace('/http:\/\/([^\s\.]+).(youtube.com\/watch\?v=)([0-9a-zA-Z[:punct:]]{11}+)/', '[youtube]$3[/youtube]', $message); 2) This leaves html closing character like this '/>' in the result string for some strange reason. $message = preg_replace('/http:\/\/([^\s\.]+).(youtube.com\/watch\?v=)([A-Za-z0-9\-]+)([^\s]*)/', '[youtube]$3[/youtube]', $message); So while both of the above work, they don't work well enough for production site. Just to clearify again, the idea is to preg_replace only youtube link with videoid in the $message, and then simply put it in the tag. Just like in the above examples, but hopefully to work as it should. If some of PHP/regexp gurus could help me out, that would be fantastic. Yes, both of the above go in adequate places in /Sources/Subs.php, but i just can't solve this regex portion of autoreplacer. Many thanks in advance! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.