Reprint: http://www.jb51.net/article/52916.htm
In fact, I in the "text in the URL to a clickable link JavaScript, PHP custom Function," the article describes how the PHP code implementation of the URL into a link to the method, today to introduce a more concise version, first look at the source code of PHP:
/**
* Author:seedz
* from:http://code.seebz.net/p/autolink-php/
**/
function Autolink ($str, $attributes = Array ()) {
$attrs = ";
foreach ($attributes as $attribute = = $value) {
$attrs. = "{$attribute}=\" {$value}\ "";
}
$str = '. $str;
$str = Preg_replace (' ([^ ' =\ ';]) ((HTTP|HTTPS|FTP|FTPS)://[^\s<]+[^\s<\.)]) ' I ', ' $1$2 ', $str);
$str = substr ($str, 1);
return $str;
}
How, very concise! Look at the API documentation for the function:
Grammar
String Autolink (String $str [, Array $attributes = Array ()])
Parameter introduction
str– Required (String type data). You need to query for the replaced text.
Attributes-Optional (Array type data). Replaces some optional parameters for the link.
return value
Returns the replaced text.
Autolink () Call method
Autolink is also very convenient to use, we can only pass one parameter, which is required to replace the character text. For example:
$str = ' A link:http://example.com/?param=value#anchor. ';
$str = Autolink ($STR);
Echo $str; A Link:http://example.com/?param=value#anchor.
?>
In addition, we can set some additional parameters of the link, you can let the generated link in a new window open, or do not want to search index to replace the link of index . For example:
$str = ' http://example.com/';
$str = Autolink ($str, Array ("target" = "_blank", "rel" = "nofollow"));
Echo $str; http://example.com/
?>
The above describes the PHP implementation of the text of the URL into a link to the Auolink, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.