PHP: STR replace by link

前端 未结 2 406
野的像风
野的像风 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:23

    Hey! Try this code (found at php.net somewhere):

    function format_urldetect( $text )
    {
    
      $tag = " rel=\"nofollow\"";
      //
      // First, look for strings beginning with http:// that AREN't preceded by an \s]+[\w])/i", "\\0", $text );
      //
      // Second, look for strings with casual urls (www.something.com...) and make sure they don't have a href tag OR a http:// in front,
      // since that would have been caught in the previous step.
      //
      $text = preg_replace( "/(?\s]+[\w])/i", "\\0", $te
    xt );
      $text = preg_replace( "/(?\s]+[\w])/i", "\\0", $t
    ext );
      return $text;
    }
    

    Uhm, broken indentation. try this http://triop.se/code.txt

提交回复
热议问题