shortysbest Posted November 28, 2010 Share Posted November 28, 2010 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/220031-replace-string-with-a-single-link-nothing-else/ Share on other sites More sharing options...
brianlange Posted November 28, 2010 Share Posted November 28, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/220031-replace-string-with-a-single-link-nothing-else/#findComment-1140517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.