PHP Regex to convert text before colon to link

前端 未结 5 941
逝去的感伤
逝去的感伤 2021-01-25 04:40

I need to find the first occurance of a colon \':\' and take the complete string before that and append it to a link.

e.g.

username: @twitter nice site!          


        
5条回答
  •  忘了有多久
    2021-01-25 05:41

    I have not tested the code, but it should work as is. Basically you need to capture after @twitter too.

    $description = preg_replace("%([^:]+): @twitter (.+)%i", 
        "@\\1: \\2", 
        $description);
    

提交回复
热议问题