How to Allow Users to add Youtube Videos

Discussion in 'PHP' started by David Holland, Dec 9, 2010.

  1. #1
    How do I allow users to embed videos into my site? They will input the code on one page and the video will show on another page, how do i do this please help me thank you
     
    Last edited: Dec 9, 2010
    David Holland, Dec 9, 2010 IP
  2. mweldan

    mweldan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    bbcode. search bbcode on php.net.
     
    mweldan, Dec 9, 2010 IP
  3. David Holland

    David Holland Active Member

    Messages:
    155
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Hi, I looked but i don't understand any on it, I was hoping some could tell what codes i got to use and where i put them.
     
    David Holland, Dec 9, 2010 IP
  4. mweldan

    mweldan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sorry about that. even bb_code_create() not available on my machine. php 5.2.3 windows.

    i give it a try.
     
    mweldan, Dec 9, 2010 IP
  5. mweldan

    mweldan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?php
    
    if (!empty($_POST['video_id']) ){
        $video_id = $_POST['video_id']; 
        
        $pattern = '#\[youtube\](.+?)\[/youtube\]#'; 
        $convert_to_this = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/\1?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\1?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
        $user_enter_this = "[youtube]".$video_id."[/youtube]";
        
        $result = preg_replace($pattern, $convert_to_this, $user_enter_this); 
        
        echo $result;  
    }
    
    ?>
    
    <?php if (empty($_POST['video_id']) ): ?>
    <form method="post" action="">
    <input type="text" name="video_id" />
    <input type="submit" />
    </form>
    <?php endif; ?>
    
    Code (markup):
    1. user enter [youtube]video_id[/youtube] example: [youtube]yvuOtlpSAeY[/youtube]
    2. then it will be converted to embed video tag
    3. then you can add this on your wysiwyg editor
     
    mweldan, Dec 9, 2010 IP
  6. backlinkneeded

    backlinkneeded Member

    Messages:
    285
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #6
    i will try that. and tell you the status on it
     
    backlinkneeded, Dec 22, 2010 IP