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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:58:21+00:00 2026-05-26T01:58:21+00:00

function link_it($text) { $text= preg_replace(/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\\n\r\t<]*)/is, $1$2<a href=\$3\ target=\_blank\>$3</a>, $text); $text= preg_replace(/(^|[\n ])([\w]*?)((www|ftp)\.[^

  • 0
function link_it($text)
{
    $text= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" target=\"_blank\">$3</a>", $text);  
    $text= preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" target=\"_blank\">$3</a>", $text);  
    $text= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:$2@$3\" target=\"_blank\">$2@$3</a>", $text);  
    return($text);  
}

That’s the working code.

I’m working on a new function

function shorturl2full($url)
{
    echo 'URL IS: ' . $url;
    return "FULLLINK";
}

The idea is to take the url and return it back. Later going to work on turning it in to the full url. So like t.co will be full url they will see.

$text= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" target=\"_blank\">" .  shorturl2full("$3") . "</a>", $text);  
        $text= preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" target=\"_blank\">" .  shorturl2full("$3") . "</a>", $text);  
        $text= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:$2@$3\" target=\"_blank\">$2@$3</a>", $text);  
        return($text);  
}

Is my bad try at it.

So if you click the link it should use the original but the one you see should be the output of shorturl2full

So like <a href="t.co">FULLLINK</a>

I want to attempt to write the shorturl2full function on my own and i think i have a very great idea on how to do it. The problem is in the link_it function… It needs to pass the url to the shorturl2full function and display what ever it returned.

  • 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-26T01:58:21+00:00Added an answer on May 26, 2026 at 1:58 am

    You can use preg_replace_callback instead of preg_replace http://nz.php.net/manual/en/function.preg-replace-callback.php

    function link_it($text)
    {
        $text= preg_replace_callback("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is",  'shorturl2full', $text);  
        $text= preg_replace_callback("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is",  'shorturl2full', $text);  
        $text= preg_replace_callback("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i",  'shorturl2full', $text);  
        return($text);  
    }
    
    function shorturl2full($url)
    {
        $fullLink = 'FULLLINK';
        // $url[0] is the complete match
        //... you code to find the full link
        return '<a href="' . $url[0] . '">' . $fullLink . '</a>';
    }
    

    Hope this helps

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

Sidebar

Related Questions

Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
For normal link $content = preg_replace('@(https?://([-\w\.]+)+(:\d+)?((/[\w/_\.%\-+~]*)?(\?\S+)?)?)@', '<a href=$1 target=_blank>$1</a>', $content); For Download link $content
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,
This link shows you that jQuery uses (new Function(return + data))(); for older browsers,
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
<script type=text/javascript> $(document).ready(function() { $('a.menuitem').click(function() { var link = $(this), url = link.attr(href); var
I have a function that parses text form posts and if there's a link
i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
$(document).ready(function () { $(.LeftColumn).hide(); $(.SidebarToggle).toggle(function () { $(this).addClass(active); $(this).text(Hide Sidebar); $(this).attr(title, Hide Sidebar); $(.LeftColumn).fadeIn(fast);
I have the following code: $('a.btn-slide').toggle(function() { $(#SliderDIV).slideDown(fast); $(this).text('Hide/Show'); }); Only in Firefox, when

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.