Convert Plain URLs to Clickable Links with PHP

Here is another PHP function you are looking for that converts any plain text URL into clickable links. just copy and drop it within your PHP project and call this function wherever you need to make URLs clickable.
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
function plain_url_to_link($string) { return preg_replace( '%(https?|ftp)://([-A-Z0-9./_*?&;=#]+)%i', '<a target="blank" rel="nofollow" href="$0" target="_blank">$0</a>', $string); }

Usage

Just like example below.
PHP
  • 1
  • 2
$str = "http://www.google.com is a search website, you can also visit http://yahoo.com and http://twitter.com"; echo plain_url_to_link($str);
New question is currently disabled!