Returns same text with changed link word to full hrefs

@param string $text

@return string
966071
public static function replaceLinksInTextsWithHrefs(string $text): string
    {
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);

        $ret = ' ' . $text;

        // Replace links with http://
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace links without http://
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace email addresses
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        $ret = substr($ret, 1);

        return $ret;
    }
440495
public function replaceAllInText($text)
    {
        $uriInfo = [];

        // Collects all µlink URIs present in the text and stores them
        // in an array keyed by their offset.
        foreach ($this->getURIPatterns() as $pattern) {
            $matches = [];

            if (preg_match_all($pattern, $text, $matches,  PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
                foreach ($matches as $match) {
                    list($uri, $offset) = $match[0];

                    $uriInfo[$offset] = [
                        'uri'   => $uri,
                        'type'  => $match['type'][0],
                        'id'    => $match['id'][0],
                    ];
                }
            }
        }

        // Sorts collected URIs by descending offset to start replacements
        // by the end of the text, ensuring in this way that the next offsets
        // will stay valid after each replacement.
        krsort($uriInfo);

        // Dispatches an event to allow some alterations of URIs information
        // before transform them in standard URLs.
        $event = new EntityLinkFilterEvent($uriInfo);
        $this->eventDispatcher->dispatch(EntityLinkFilterEvent::EVENT_BEFORE_FILTER, $event);

        // Replaces µlink URIs by standard URLs.
        foreach ($event->getURIInfo() as $offset => $info) {
            // Something inserted a new entry!?
            // Ok, just ignore it.
            if (!isset($uriInfo[$offset])) {
                continue;
            }
            // Something altered the original URI!?
            // Ok, just retrieve the text's version for the next.
            if ($info['uri'] !== $uriInfo[$offset]['uri']) {
                $info['uri'] = $uriInfo[$offset]['uri'];
            }

            try {
                $uri = url($this->getEntityPath($info['type'], $info['id']));
            } catch (\Exception $e) {
                $uri = '#'; // Silent fail for frontend
            }

            $text = substr_replace($text, $uri, $offset, strlen($info['uri']));
        }

        return $text;
    }
946915
public function embedTags(string $text): string
    {
        if (strpos($text, '#') !== false) {
            $text = strtr($text, $this->getTags($text));
        }

        return $text;
    }
1257042
protected function replaceNamesIn($text)
    {
        $is_string_literal = strpos($text, "'") !== false
            || strpos($text, '"') !== false;
        if ($is_string_literal) {
            return $text;
        }

        $word = '[a-z_][a-z0-9_]+';

        $find = "/(\\b)($word)\\.($word)(\\b)/i";

        $repl = '$1`$2`.`$3`$4';

        $text = preg_replace($find, $repl, $text);

        return $text;
    }
741167
private function filter($text)
    {
        $text = preg_replace("/[^&a-z0-9-_\s']/i", '', $text);
        $text = str_replace(' ', $this->separator, $text);
        $text = trim(preg_replace("/{$this->separator}{2,}/", $this->separator, $text), $this->separator);

        return $text;
    }
1310217
private function getTranslatedText($text)
    {
        if ($this->isEnglish($text)) {
            return $text;
        }
        $text = $this->removeSegment($text);
        $url = $this->getTranslateUrl($text);
        $response = $this->http->get($url);

        return $this->getTranslation(json_decode($response->getBody(), true));
    }
1263348
static public function linkUrls($text, array $attribs = array()) {
        $htmlAttribs = array();
        foreach ($attribs as $name => $value) {
            $htmlAttribs[] = $name . '="' . $value . '"';
        }
        $htmlAttribs = implode(' ', $htmlAttribs);
        $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : '';

        $regexpProtocol = "/(?:^|\s)((http|https|ftp):\/\/[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i";
        $regexpWww      = "/(?:^|\s)((www\.)[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i";

        $text = preg_replace($regexpProtocol, " <a href=\"\\1\"$htmlAttribs>\\1</a>\\3 ", $text);
        $text = preg_replace($regexpWww, " <a href=\"http://\\1\"$htmlAttribs>\\1</a>\\3 ", $text);
        return trim($text);
    }
1319244
public function linkTo($text, $urlOptions, array $attrs = [])
    {
        $url = $this->parseUrlOptions($urlOptions);
        return $this->contentTag('a', $text, array_merge(['href' => $url], $attrs));
    }
1167029
public function links($text, $limit = null)
    {
        // Set link limit
        $limit = is_null($limit) ? $this->getConfig('defaultMaxLinks', 10) : $limit;

        // Normalize string before passing
        $text = $this->prepare($text);

        // Get link matches
        preg_match_all("!((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)!", $text, $matches);

        return (count($matches[0]) >= (int) $limit);
    }
64822
public static function a(string $text, string $target = null): string
    {
        return preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@',
          "<a href=\"\$1\"" . ($target != null ? " target=\"{$target}\"" : '') . ">$1</a>", $text);
    }
765314
protected function doAutoLinks($text)
    {
        if(!$this->features['auto_mailto'])
        {
            return preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
            array(&$this, '_doAutoLinks_url_callback'), $text);
        }

        return parent::doAutoLinks($text);
    }
730823
protected function replaceTextTokens($text)
    {
        foreach ($this->tokens as $key => $val) {
            $text = str_replace('<' . $key . '>', $val, $text);
        }

        return $text;
    }
313432
public static function strip(string $text): string
    {
        if (false === \strpos($text, '</')) {
            return $text;
        }

        // $text = \strip_tags($text);
        return \preg_replace(self::STRIP_TAG, '', $text);
    }
1230774
public function makeHTML($text)
    {
        $html = $text;

        if ($this->defaultActions['makeLinks']) {
            $html = $this->makeLinks($html);
        }

        if ($this->defaultActions['convertLineEndings']) {
            $html = $this->convertLineEndings($html);
        }

        return $html;
    }
1242529
public function text($text)
    {
        foreach ($this->_data as $macros => $value) {
            $macros = '{' . $macros . '}';
            $text   = preg_replace('#' . $macros . '#ius', $value, $text);
        }

        return $text;
    }
581295
public static function strtolower($text) {
    if (static::getStatus() == static::STATUS_MULTIBYTE) {
      return mb_strtolower($text);
    }
    else {
      // Use C-locale for ASCII-only lowercase.
      $text = strtolower($text);
      // Case flip Latin-1 accented letters.
      $text = preg_replace_callback('/\xC3[\x80-\x96\x98-\x9E]/', '\Drupal\Component\Utility\Unicode::caseFlip', $text);
      return $text;
    }
  }
162906
public static function nl2paragraph($text)
    {
        $paragraphs = explode("\n", $text);

        foreach ($paragraphs as &$paragraph) {
            $paragraph = "<p>$paragraph</p>";
        }

        return implode('', $paragraphs);
    }