Find the urls inside a string a put them inside anchor tags.

@usage __::urlify("I love https://google.com");
>> 'I love <a href="https://google.com">google.com</a>'

@param string $string

@return string|mixed
773211
public static function urlify(string $string)
    {
        /* Proposed by:
         * Søren Løvborg
         * http://stackoverflow.com/users/136796/soren-lovborg
         * http://stackoverflow.com/questions/17900004/turn-plain-text-urls-into-active-links-using-php/17900021#17900021
         */

        $rexProtocol = '(https?://)?';
        $rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
        $rexPort = '(:[0-9]{1,5})?';
        $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?';
        $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
        $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';

        return preg_replace_callback(
            "&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&",
            function ($match) {
                $completeUrl = $match[1] ? $match[0] : "http://{$match[0]}";

                return '<a href="' . $completeUrl . '">' . $match[2] . $match[3] . $match[4] . '</a>';
            },
            htmlspecialchars($string)
        );
    }
127481
public static function makeValidUrl($string)
    {
        $protocols = ['http://', 'https://', 'ftp://'];

        if ($string != '') {
            foreach ($protocols as $p) {
                if (substr($string, 0, strlen($p)) == $p) {
                    return $string;
                }
            }
        }

        if ($string != '' && $string != 'http://') {
            $string = 'http://' . $string;
        }

        return $string;
    }
182405
public function friendlyUrl($string)
    {
        /**
         * @var Helper $helper
         */
        $helper = $this->helper;

        $string = preg_replace('~[\s\t\n\r]+~', '-', $string);

        $string = $helper->str()->low($string);
        $string = $helper->str()->translit($string);

        return trim(preg_replace('~[^a-z0-9-]+~', '', $string), '-');
    }
427931
public function parseFromString($string){
		$dom = $this->html5->loadHTML($string);
		if( is_a($dom, 'DOMDocument') ){
			return $dom;
		}else{
			return false;
		}
	}
1237437
public static function validateURL($string)
    {
        if (filter_var($string, FILTER_VALIDATE_URL)) {
            return (string)$string;
        }

        throw new InvalidArgumentException(
            sprintf(
                'Provided string "%1$s" was not a valid URL.',
                $string
            )
        );
    }
86180
public static function encode($string)
    {
        if (is_array($string)) {
            foreach ($string as $k => $substring) {
                $string[$k] = static::encode($substring);
            }
        } else {
            $string = urlencode($string);
        }

        return $string;
    }
641541
public function injectParams($string, $params = array())
    {
        $links = preg_split('#(<a\b[^>]+>)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
        $old   = $links;

        foreach ($links as &$match) {
            if (preg_match('/<a\b/', $match) && !preg_match('/(?:#|mailto)/', $match)) {
                preg_match('/^([^"]+")([^"]+)/', $match, $matches);
                if ($matches) {
                    $link = html_entity_decode($matches[2]);
                    if (strpos($link, "?") === false) {
                        $link .= "?";
                    } else {
                        $link .= "&";
                    }

                    $link .= http_build_query($params);

                    $match = str_replace($matches[2], $link, $match);
                }
            }
        }

        $string = str_replace($old, $links, $string);
        return $string;
    }
913329
protected function replaceWithVariables($string)
    {
        if (preg_match_all('/:([a-z_]+)/', $string, $matches)) {
            list(
                $original,
                $vars
            ) = $matches;

            foreach ($vars as $key => $var) {
                if (isset($this->vars[$var])) {
                    $string = str_replace($original[$key], $this->vars[$var], $string);
                }
            }
        }

        return $string;
    }
1338929
public static function urlize($text)
    {
        $text = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $text);
        $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $text);
        $text = preg_replace("/@(\w+)/", "<a href=\"http://twitter.com/\\1\">@\\1</a>", $text);
        $text = preg_replace("/([^&]|^)#(\w+)/", "\\1<a href=\"http://twitter.com/search/\\2\">#\\2</a>", $text);

        return $text;
    }
1015084
protected function underscoreToSpace($string)
    {
        $string = strtolower($string);
        $string = preg_replace('#_(?=[a-z])#', ' ', $string);
        $string = substr(ucwords($string), 0);
        $string = substr(ucwords('x'.$string), 1);

        return $string;
    }
970219
public function EscapeString($String) {
      $Array = FALSE;
      if (substr($String, -2) == '[]') {
         $String = substr($String, 0, -2);
         $Array = TRUE;
      }
      $Return = urlencode(str_replace(' ', '_', $String));
      if ($Array === TRUE) $Return .= '[]';

      return str_replace('.', '-dot-', $Return);
   }
438425
public function nl2p($string)
    {
        // replace lineFeed with <br /> tag
        $lineFeed = chr(10);
        $value = preg_replace('#'.$lineFeed.'#', '<br />', $string);

        // replace double <br /> tags with </p><p> tags
        $pattern = '#<br />([ ]*)<br />#';
        $replacement = '</p><p>';
        $result = preg_replace($pattern, $replacement, $value);

        return $result;
    }
483704
public function format($string) {
        if ($this->isAnsiEnabled()) {
            return $this->formatAnsi($string);
        }

        return $this->formatPlain($string);
    }
1036165
public static function stringToArray($string)
    {
        if (!preg_match("@^{.*?}$@", $string)) {
            return $string;
        }
        $parts = explode(',', substr($string, 1, -1));
        foreach ($parts as &$part) {
            $part = self::stringToArray($part);
        }
        return $parts;
    }
194490
public function removeTags($string)
    {
        // Remove HTML Tags:
        
        $string = preg_replace('/<[^>]*>/', ' ', $string);
        
        // Remove Control Characters:
        
        $string = str_replace("\r", '',  $string);  // replace with empty space
        $string = str_replace("\n", ' ', $string); // replace with single space
        $string = str_replace("\t", ' ', $string); // replace with single space
        
        // Remove Multiple Spaces:
        
        $string = trim(preg_replace('/ {2,}/', ' ', $string));
        
        // Answer String:
        
        return $string;
    }
715263
public function singularize($string)
    {
        $this->camelCased = $this->isStringCamelCased($string);

        $matches = $this->findEndingBasedMatch($string);

        if ( $matches !== false) return $matches['singular'];

        if (preg_match('#^(.*)en$#i', $string, $matches)) {
            return $matches[1];
        }

        return $string;
    }
677994
public static function UrlAmigavel($string){
		    $table = array('Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z','ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c','À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A','Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E','Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I','Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O','Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U','Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a','å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e','ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i','ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o','ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u','ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b','ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r');
	    	$string = strtr($string, $table);
	    	$string = strtolower($string);
	    	$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
	    	$string = preg_replace("/[\s-]+/", " ", $string);
	    	$string = preg_replace("/[\s_]/", "-", $string);
	    	return $string;
		}