function make_clickable($ret) {}

Convert plaintext URI to HTML links.
Converts URI, www and ftp, and email addresses. Finishes by fixing links within links.


  • string $ret: Content to convert URIs.

Return values

returns:Content with converted URIs.

Source code

function make_clickable($ret) {

	$ret = ' ' . $ret;

	// in testing, using arrays here was found to be faster

	$save = @ini_set('pcre.recursion_limit', 10000);

	$retval = preg_replace_callback('#(?<!=[\'"])(?<=[*\')+.,;:!&$\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#%~/?@\[\]-]{1,2000}|[\'*(+.,;:!=&$](?![\b\)]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret);

	if (null !== $retval )

		$ret = $retval;

	@ini_set('pcre.recursion_limit', $save);

	$ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret);

	$ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);

	// this one is not in an array because we need it to run last, for cleanup of accidental links within links

	$ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);

	$ret = trim($ret);

	return $ret;




No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: