Jump to content

Recommended Posts

what i'm attempting to do is to build a video embedding system into my comment stream, and I have all of that working for the most part,but what I am trying to do now is to have the link preview before you post the status, I just want it to allow 1 link to pass through to be posted to the php preview page.

 

so if you type in the textbox something like "check this video out 

then I just want it to get the video link and nothing else, and I don't want it to allow double links, like if someone posts:

"check this video out

 

i just want it to return the first link once.

 

This is the code i'm using to change the text into a link, right now it shows the video and everything but it just shows the other text, and double links.

 

 

var comment = encodeURIComponent($("#comment").val());

  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  var ab = comment.replace(exp,"<a href='$1'>$1</a>"); 

 

 

This works but I'd like to see the solution that uses replace.

 

var message = "check this video out http://www.youtube.com/watch?v=3kBbun8xdDQ http://www.youtube.com/watch?v=3kBbun8xdDQ";
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  var m = message.match(exp);
  var link = '<a href="' + m[0] + '">' + m[0] + '</a>';
  alert(link);

 

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.