选择语言 :

 Core_Text::auto_link_urls

Converts text anchors into links. Existing links will not be altered.

echo Text::auto_link_urls($text);

This method is not foolproof since it uses regex to parse HTML.
string Core_Text::auto_link_urls( string $text )
uses
HTML::anchor

参数列表

参数 类型 描述 默认值
$text string Text to auto link
返回值
  • string
File: ./core/classes/text.class.php
public static function auto_link_urls($text)
{
    // Find and replace all http/https/ftp/ftps links that are not part of an existing html anchor
    $text = preg_replace_callback('~\b(?<!href="|">)(?:ht|f)tps?://\S+(?:/|\b)~i', 'Text::_auto_link_urls_callback1', $text);

    // Find and replace all naked www.links.com (without http://)
    return preg_replace_callback('~\b(?<!://|">)www(?:\.[a-z0-9][-a-z0-9]*+)+\.[a-z]{2,6}\b~i', 'Text::_auto_link_urls_callback2', $text);
}