The following function will parse a given text and convert all the urls into links. It does this using regular expressions. It converts email addresses to mailto links as well.
Code
1
2
3
4
5
6
7
| function parse_links( $str ) { $str = preg_replace( '/(([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6})/' , '<a href="mailto:$1">$1</a>' , $str ); return $str ; } |
0 comments:
Post a Comment