Conditions | 3 |
Paths | 2 |
Total Lines | 21 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
37 | public function convertLinks(string $text, array $options = []): string |
||
38 | { |
||
39 | // https://bitbucket.org/kwi/urllinker/ |
||
40 | $text = preg_replace('#(script|about|applet|activex|chrome):#is', '\\1:', $text) ?: ''; |
||
41 | $ret = ' '.$text; |
||
42 | |||
43 | $attr = ''; |
||
44 | foreach ($options as $key => $value) { |
||
45 | $attr .= ' '.$key.'="'.$value.'"'; |
||
46 | } |
||
47 | |||
48 | // Replace Links with http:// |
||
49 | $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", '\\1<a href="\\2"'.$attr.'>\\2</a>', $ret); |
||
50 | |||
51 | // Replace Links without http:// |
||
52 | $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", '\\1<a href="http://\\2"'.$attr.'>\\2</a>', $ret); |
||
53 | |||
54 | // Replace Email Addresses |
||
55 | $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '\\1<a href="mailto:\\2@\\3"'.$attr.'>\\2@\\3</a>', $ret); |
||
56 | |||
57 | return substr($ret, 1); |
||
58 | } |
||
60 |