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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:44:19+00:00 2026-06-14T01:44:19+00:00

I have a custom edit user interface where I allow the user to enter

  • 0

I have a custom edit user interface where I allow the user to enter their own URL’s, and so far I have the regex to find the URL’s and turn them all into clickable html links. But I’d also like to give the user the option to enter their own link title, similar to the format here on StackOverflow:

[Name of Link](http://www.yourlink.com/)

How would I alter the code below to extract the title from the brackets, the URL from the parenthesis, AND also turn a regular URL into a clickable link (even if they just enter http://www.yourlink.com/ without a title)?

$text = preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
                       '<a href="\\1" target="_blank">\\1</a>', $text);
$text = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
                       '\\1<a href="http://\\2" target="_blank">\\2</a>', $text);
$text = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i',
                       '<a href="mailto:\\1">\\1</a>', $text);
  • 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-14T01:44:21+00:00Added an answer on June 14, 2026 at 1:44 am

    Firstly you have to process these links with description, like this:

    $text = preg_replace(
        '/\[([^\]]+)\]\((((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\)/i',
        '<a href="\\2" target="_blank">\\1</a>', 
        $text
    );
    

    But now, regular URLs placed in href will match in next replace iteration for regular links, so we need to modify that to exclude it, for example match only when it is not preceded with ":

    $text = preg_replace(
        '/(^|[^"])(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
        '\\1<a href="\\2" target="_blank">\\2</a>', 
        $text
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom WinForms control (inherits from control, i.e. without user interface jsut
On my iphone app, I have a UITableView in edit mode, containing custom UITableViewCell.
I have custom UITableViewCell s as well as headers and footers. Each of them
I have a RadGrid with a custom edit form ( FormTemplate ). The grid
I create some custom user profile fields, I just create a edit user profile
I have a custom Title Bar so I want that when the user types
I've spent a lot of time with this problem. I have custom user control
I have a custom user control DatePicker.cs. Inside of another piece of code I
I have a custom WPF user control called a TimeoutPanel that I am trying
I have a custom list with one textView and one edit text in each

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.