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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:48+00:00 2026-05-26T05:00:48+00:00

Lets say I have a text such as this This is a long text.

  • 0

Lets say I have a text such as this
“This is a long text. It contains 150 characters. You can find more about this text on this link http://www.somewebsite.com/RDFCCSDVDS“.

So in above text I want to find that link and convert it into a link so that when user clicks on it, the user will be taken directly to this website.

How can I achieve this goal?

  • 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-26T05:00:49+00:00Added an answer on May 26, 2026 at 5:00 am

    I suspect that I could much improve upon this, though at the minute this is the best I can offer (albeit I think that some kind of replace might work more efficiently):

    var $words = $('p').text().split(' ');
    for (i in $words) {
        if ($words[i].indexOf('http://') == 0) {
            $words[i] = '<a href="' + $words[i] + '">' + $words[i] + '</a>';
        }
    }
    
    $('p').html($words.join(' '));
    

    JS Fiddle demo.

    A slightly improved version of the above (but good lord, it’s ugly…):

    var punctuation = ['!',"'",'"',',','.'];
    $('p').each(
        function(){
            $words = $(this).text().split(' ');
            for (i in $words){
                if ($.inArray($words[i].charAt(0),punctuation) > -1 && $words[i].indexOf('http://') == 1){
                    alert($words[i]);
                }
                else if ($.inArray($words[i].charAt($words[i].length - 1),punctuation) > -1 && ($words[i].indexOf('http://') == 1 || $words[i].indexOf('http://') == 0)){
                    $words[i] = '<a href="'+$words[i].substring(0,$words[i].length-1)+'">' + $words[i].substring(0,$words[i].length-1) + '</a>' + $words[i].charAt($words[i].length-1);
                }
                else if ($words[i].indexOf('http://') == 0){
                    $words[i] = '<a href="' + $words[i] + '">' + $words[i] + '</a>';
                }
            }
            $(this).html($words.join(' '));
        });
    

    JS Fiddle demo.

    I’m not quite sure what to do about quoted links, though (text such as "http://google.com", for example); and, honestly, I think that regex is probably the far, far better approach to this problem.

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

Sidebar

Related Questions

lets say I have a text file with lines as such: [4/20/11 17:07:12:875 CEST]
Lets say I have a text box which should have a default value.... and
I have a few text boxes and buttons on my form. Lets say txtBox1
Let's say you have a text file like this one: http://www.gutenberg.org/files/17921/17921-8.txt Does anyone has
Let's say I have a text file that is 100 lines long. I want
Let's say I have a line of text like this Small 0.0..20.0 0.00 1.49
Lets say, I have the following text file: Listing 1: Endianess=little AddressModel=32 typedef struct{
lets say i have a list of urls such as http://stackexchange.com https://stackoverflow.com/users/login http://careers.stackoverflow.com http://chat.stackoverflow.com
Let's say I have some HTML like so: <div id=text>This <i>is</i> a <b>test</b>. Do
Let's say I have a text file of basic mathematical functions. I want to

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.