PHP: STR replace by link

前端 未结 2 390
野的像风
野的像风 2021-01-17 04:32

i have this PHP chatbox.

If i would type a link in the chatbox, it would not display it as a link.

How can i use STR replace to do this?

It should re

2条回答
  •  [愿得一人]
    2021-01-17 05:10

    You should use regex instead. look at preg_replace

    $regex = '`(\s|\A)(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)`ism';
    $replace = '$1$2://$3$4'
    
    $buffer = preg_replace($regex,$replace,$buffer);
    

提交回复
热议问题