简体   繁体   English

使链接可点击

[英]Make link clickable

My code replacing "default" link to clickable link if you know what i mean ;/ When in text is only 1 url all woks fine but when in string is more than 1 url all links begin to be the same. 如果您知道我的意思,我的代码将“默认”链接替换为可点击的链接; /当文本中只有1个网址时,所有炒锅都可以,但是当字符串中的内容超过1个网址时,所有链接都将开始相同。 On example 在例子

"Here is my first video LINK1 and here is my second video LINK2" “这是我的第一个视频LINK1,这是我的第二个视频LINK2”

After do function this text look like this: 执行功能后,此文本如下所示:

"Here is my first video LINK1 and here is my second video LINK1" “这是我的第一个视频LINK1,这是我的第二个视频LINK1”

LINK2 begin to be LINK1 LINK2开始成为LINK1

My function 我的功能

function DoLinks($link){
    $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

    $text = $link;
    if(preg_match($reg_exUrl, $text, $url)) {
        // DO IT!
        $linh = $url[0];
        return preg_replace($reg_exUrl, "<a class='linka' href='$linh'>$linh</a> ", $text);
    } else {
        return $text;
    }
}

My question is how to do that LINK2 begin to be LINK2 not LINK1 我的问题是如何使LINK2开始成为LINK2而不是LINK1

maybe you want something like: 也许您想要类似的东西:

function DoLinks($text) {   
    return preg_replace ('/((?:http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*)?)/', '<a href="$1">$1</a>', $text);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM