JBZoo\Utils\Url::parseLink PHP Метод

    public static function parseLink($text)
    {
        $text = preg_replace('/'/', ''', $text);
        // IE does not handle ' entity!
        $sectionHtmlPattern = '%            # Rev:20100913_0900 github.com/jmrware/LinkifyURL
                                            # Section text into HTML <A> tags  and everything else.
             (                              # $1: Everything not HTML <A> tag.
               [^<]+(?:(?!<a\\b)<[^<]*)*     # non A tag stuff starting with non-"<".
               | (?:(?!<a\\b)<[^<]*)+        # non A tag stuff starting with "<".
             )                              # End $1.
             | (                            # $2: HTML <A...>...</A> tag.
                 <a\\b[^>]*>                 # <A...> opening tag.
                 [^<]*(?:(?!</a\\b)<[^<]*)*  # A tag contents.
                 </a\\s*>                    # </A> closing tag.
             )                              # End $2:
             %ix';
        return preg_replace_callback($sectionHtmlPattern, array(__CLASS__, '_linkifyCallback'), $text);
    }

Usage Example

Пример #1
0
 public function testParseLinky()
 {
     $input = 'great websites: http://www.google.com?param=test and http://yahoo.com/a/nested/folder';
     $expect = 'great websites: <a href="http://www.google.com?param=test">http://www.google.com?param=test</a>' . ' and <a href="http://yahoo.com/a/nested/folder">http://yahoo.com/a/nested/folder</a>';
     is($expect, Url::parseLink($input));
     is($expect, Url::parseLink($expect));
 }