Replacing Text link as link with preg_replace

后端 未结 2 1303
南旧
南旧 2021-01-19 05:50

I seem to be having an issue replacing a text link with a link to the site posted, it isn\'t linking.

The code:

$status_text = preg_replace(\'#(\\A|[         


        
2条回答
  •  北海茫月
    2021-01-19 06:04

    Can you just try this:

    function makeClickableLinks($s) {
      return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '$1', $s);
    }
    

    To test it, try this:

    echo makeClickableLinks('Hello world, you go to www.google.com to check! also http://www.google.com/ works too!');
    

    Demo here: http://codepad.viper-7.com/hkOdCM

提交回复
热议问题