I am creating a facebook - style site, but have hit a brick wall when getting a link and if it is a youtube video, display it as an embeded youtube video.
Basically - if a database value contains the link: http://www.youtube.com/foo it embeds that like facebook does.
THIS IS NOT Facbebook API and I don't mind how to do it.
Thanks.
If someone submits a YouTube URL, use YouTube's JavaScript API to embed the player. http://code.google.com/apis/youtube/js_api_reference.html#Functions
You'll probably want to use cueVideoByUrl()
.
To locate a YouTube URL within user input, probably the easiest thing to do is to create a regular expression to find it. This can be complicated if you allow HTML tags in user input etc., but if you've correctly sanitized the user input and are not allowing tags or special characters, it should be pretty straightforward.