Skip to content

Instantly share code, notes, and snippets.

@RoesWibowo
Created July 31, 2015 07:07
Show Gist options
  • Save RoesWibowo/e320e72a81c15c6a9218 to your computer and use it in GitHub Desktop.
Save RoesWibowo/e320e72a81c15c6a9218 to your computer and use it in GitHub Desktop.
Convert http, https, ftp to link in a text
<?php
function convertTextWithLink($text) {
$result = preg_replace('%(((f|ht){1}tp[s]?://)[-a-zA-^Z0-9@:\%_\+-.,!~#?&//=]+)%i','<a href="\\1" target="_blank">\\1</a>', $text);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment