PHP Secure Auto-Link Maker

Submitted by:Andery Smith

Date added:01 October, 2014

Category:PHP

PHP example code for secure link conversion

Tags: link conversion , auto link

Code Snippet:

<?PHP

FUNCTION convert_links($str) {
$replace = <<<EOPHP
'<a href="'.htmlentities('\\1').htmlentities('\\2').//remove line break
'">'.htmlentities('\\1').htmlentities('\\2').'</a>'
EOPHP;
$str = PREG_REPLACE('#(http://)([^\s]*)#e', $replace, $str);
RETURN $str;
}

?>
 
 

Comments