Last active
December 9, 2015 00:59
-
-
Save katzueno/49451e38f554a51177ae to your computer and use it in GitHub Desktop.
Autolink of Forum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public static function autolink($input) { | |
$output = preg_replace_callback("/[\s| ](http:\/\/|https:\/\/|(www\.))(([^\s<]{4,160})[^\s<]*)/", | |
create_function( | |
'$matches', | |
'return "<a href=\"http://".$matches[2].$matches[3]."\" title=\"http://".$matches[2].$matches[3]."\" rel=\"nofollow\" target=\"_blank\">". | |
(strlen("http://".$matches[2].$matches[4])>160?"http://".$matches[2].$matches[4]."...":"http://".$matches[2].$matches[4])."</a>";' | |
), $input); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment