[^\s()]+)|(?R))*\) | # else match a link with title ^(www\.|https?:\/\/)(([^\s<>()]+)|(?R))+(?context) && preg_match($regex, $text, $matches) ) { // Do not allow links within links. return [ ['autoUrl', $matches[0]], strlen($matches[0]) ]; } return [['text', substr($text, 0, 4)], 4]; } protected function renderAutoUrl($block): string { $href = $block[1]; $text = $href; if (!str_starts_with($href, 'http')) { $href = 'http://' . $href; } $href = $this->escapeHtmlEntities($href, ENT_COMPAT); $decoded = rawurldecode($text); $secured = preg_match('//u', $decoded) ? $decoded : $text; $text = $this->escapeHtmlEntities( $secured, ENT_NOQUOTES | ENT_SUBSTITUTE ); return "$text"; } abstract protected function escapeHtmlEntities($text, $flags = 0); }