communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "string handling" - download "autolink" - open demo of "autolink"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

string handling - autolink was created/last modified on Fri 19 Mar 2004 7:12 PM

this script will detect URLs in a string and automatically create a link to this URL.
it removes the query-string and shows only the top-level of the site linked to as text.
  
  <?
   
   $txt
= '<p>this is a teststring with an url in it http://fundisom.com/phpsnippets/snip and its enough to be like that';
   
$txt = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '<a href="\0">\4</a>', $txt );
   
   echo
$txt;
   
   
?>

learn more about some of the PHP functions used in this snippet: echo, link, preg_replace

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

go to PHParadise to get free PHP, Javascript and FlashMX code