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 8077449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:28:43+00:00 2026-06-05T15:28:43+00:00

I use this function for transforming URLs to images on output. function InsertLink(T){ var

  • 0

I use this function for transforming URLs to images on output.

function InsertLink(T){
 var Out = '';
 var T1=T;
 var LinkR = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?([^?#]*\.(?:jpg|jpeg|gif|png))/;
 var Pos=0;
 for(var N=0;(N=T1.search(LinkR))!==-1;){
    var S1 = T1.match(LinkR)[0];
    var S1L = S1.length;
    Out += T1.substr(0,N)+"<a href='"+S1+"' target='_blank'><img class='sml' src='"+S1+"' /></a><br />";
    T1 = T1.substr(N+S1L);
    Pos=N+S1L;
 };
 Out+=T1;
 return Out;
}

But it working only for one URL in post body. If text contains more than one URL, all URLs attached to one image (“broken” image).

What’s wrong?

  • 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-06-05T15:28:44+00:00Added an answer on June 5, 2026 at 3:28 pm

    See the jsFiddle for how to do it, the code you need is in the replaceWithImgLinks function

    http://jsfiddle.net/C3zF6/1/

    I had trouble getting your regex to work so I used the one from here: What is a good regular expression to match a URL?

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

Sidebar

Related Questions

I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
I am confused why codeigniter wont let me use this: $(function() { var csrf
I want to take output these three strings, I use this code function sectionString()
I use this function to read information from xls (2003) file var connectionString =
I use this function to resize images but i end up with ugly creepy
I use this function to scroll to a desired container: function scrolear(destino){ var stop
I can't find any example signatures for .NET to use this function (GetSystemDEPPolicy). http://msdn.microsoft.com/en-us/library/windows/desktop/bb736298(v=vs.85).aspx
I use this Processing Output function _output(), it work very good with me, but
I've got this JS Object: var test = {code_operateur:[],cp_cult:[,],annee:[2011],ca_cult:[]} When I use this function:
I use this function to make links clickable: function clickable($text) { $text = preg_replace(/(https?|ftps?|mailto):\/\/([-\w\p{L}\.]+)+(:\d+)?(\/([\w\p{L}#-;+-\/_\.]*(\?\S+)?)?)?/u,

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.