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

  • Home
  • SEARCH
  • 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 1014347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:14:24+00:00 2026-05-16T10:14:24+00:00

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,

  • 0

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", '<a target="_blank" href="$0">$0</a>', $text);
   return $text;
}

It works fine but there is one little problem. If the $text variable contains a string like this:

http://example.com

some text

i.e. link, line break(s) and some text, I get incorrect result. Instead of this:

<a target="_blank" href="http://example.com">http://example.com</a>

it becomes:

<a target="_blank" href="http://example.com<br">http://example.com</a>
/>

some text

Here is how I display text on my site:

<?php echo clickable(nl2br($db['content'])); ?>

nl2br function converts all line breaks into html <br /> tags but this function thinks it should keep this tag in url…

Hope I’m clear 🙂

Any ideas?

  • 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-16T10:14:25+00:00Added an answer on May 16, 2026 at 10:14 am

    At the end of your pattern you have \S+ – this allows all non-space characters, including <, and the reason your regex doesn’t work as expected. I’m not quite sure what is the role of that part, consider removing the (\?\S+)? and see if it’s working for you.

    Another option is changing that group to: [^\s<]* – this will not capture spaces and the < sign, solving exactly this problem…

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A UIView's superView is assumed to be a UIView. However,… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer Take a look at JUnit, what I think you want… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer What sort of key have they provided? Assuming this key… May 16, 2026 at 6:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I use this function to make URLs to clickable links but the problem is
$(document).ready(function(){ $(a).click(function() { $(#content).load($(this).attr(href)); window.location.hash = $(this).attr(href); return false; }); }); So I use
I've got this little snippet that I use for row highlighting on an XSLT
I wanted to create a function which would return the path of the current
I'm new to web development, I'm sure there's a simple answer to this, but
Ok saddle up cowboys, because this is going to be a long one. I
Ahoy hoy everyone :) Here is a list of links. You will need it
I am trying to make a navigation that uses simple unordered lists to list
Note: This question refers to a very old version of jQuery.validate() (version 1.5). This
Can anyone instruct me on the proper way to use the MySQLi extension in

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.