Skip to content

Instantly share code, notes, and snippets.

<?php
class URL
{
public function auto($string, $type = 'both', $attr = false, $echo = false)
{
if ($type == 'both' || $type == 'url')
{
$regex = '/(?<anchor><a(?:\s+(?<attr>(?:\S+?=(?:(?:\'.*?\')|(?:".*?")\s*))+))?>(?<text>.*?)<\/a\s*>)|(?<!>)(?<url>(?<proto>https?:\/{2})(?<domain>[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,3})(?<path>\/\S*)?)/i';
return preg_replace_callback($regex, function($matches)
{