Jump to content

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/212453-youtube-auto-embedding-within-smf-board/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.