Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:52:08+00:00 2026-05-16T07:52:08+00:00

Im building my own forum where you can use diffrent types of BBcode and

  • 0

Im building my own forum where you can use diffrent types of BBcode and one of them is [youtube][/youtube] to embed youtube videos,

The idea is to make it idiot-proof, the user can enter the full lenght url or just the code to the video like this

[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg%5B/youtube%5D
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related%5B/youtube%5D
[youtube]AJ3_kndmeCg[/youtube]

Here is my code that get the code out of a full lenght url,

<?php
$getpost=$_POST['post'];  
$getpost=preg_replace("'\[youtube\].*?=(.*?)&.*?\[/youtube\]'is",'yt link is \\1',$getpost);  
$getpost=preg_replace("'\[youtube\].*?=(.*?)\[/youtube\]'is",'yt link is \\1',$getpost);  
$getpost=preg_replace("'\[youtube\](.*?)\[/youtube\]'is",'yt link is \\1',$getpost);  
?>

The results are:

yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg

It works perfectly if I only want to embed 3 youtube videos,

But if i wanted to embed 6 youtube videos like this:

[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg%5B/youtube%5D
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related%5B/youtube%5D [youtube]AJ3_kndmeCg[/youtube]
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg%5B/youtube%5D
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related%5B/youtube%5D
[youtube]AJ3_kndmeCg[/youtube]

The results are:

yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg[/youtube]
yt link is AJ3_kndmeCg
yt link is http://www.youtube.com/watch?v=AJ3_kndmeCg
[youtube]AJ3_kndmeCg

Do you see that^^ the tags still remain on two lines and one of the lines show a full lenght URL,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:52:08+00:00Added an answer on May 16, 2026 at 7:52 am

    Wow, this was a real toughie of a regex to write.

    Got it for you in one:

    $getpost=preg_replace('@\[youtube\].*?(?:v=)?([^?&[]+)(&[^[]*)?\[/youtube\]@is',
                 'yt link is \\1', $getpost);
    

    This will work for all the cases you supplied. It will not work if the link begins with a part other than ‘v=’ (for example, ‘http://www.youtube.com/watch?foo=bar&v=AJ3_kndmeCg‘).

    Enjoy!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in building my own php framework for my personal use to
I am building my own CRM access database that will contain a list of
I am building my own local search UI element that gives local search suggestions
I am learning a lot about design patterns when I am building my own
I am building a small device with its own CPU (AVR Mega8) that is
I am currently building a webshop for my own where I want to increment
I know RIM has their own IDE ( BlackBerry JDE ) for building BlackBerry
I'm building a public website which has its own domain name with pop/smtp mail
The background I'm building a fair-sized web application with a friend in my own
(source: kominetz.com ) Hello. I'm diving into iOS development and am building my own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.