Zend - The PHP Company




Text

Add Code


Enable e-mail and web addresses in a string  

Type: code fragment
Added by: russlndr
Entered: 21/12/2000
Last modified: 07/12/2000
Rating: **** (12 votes)
Views: 10101
This function add HTML code to all urls in a string and return the string with clickable urls.


<?php
// Written by Fredrik Kristiansen (russlndr at online.no)
// and Albrecht Guenther (ag at phprojekt.de).

function html_activate_links($str) {
  
$str eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)''<a href="\1" target="_blank">\1</a>'$str);
  
$str eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)''\1<a href="http://\2" target="_blank">\2</a>'$str);
  
$str eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})','<a href="mailto:\1">\1</a>'$str);
  return 
$str;
}
?>


Usage Example




Rate This Script





Search



This Category All Categories