There is a small site in which there are comments. How to ban links in the comments? I know how to disable links from http , but if they enter links like google.ru ? Without http and www ? How to ban such links?

  • Regular Expressions - PaulD
  • one
    And who is allowed to insert links at all in the comments? let everything be displayed as text, and eliminate tags !! - Yoharny Babay

2 answers 2

links like google.com? without http and www? How to ban such links?

And try to solve the reverse problem: how to make such links clickable. When you decide it, yes, so that the recognition is 1) without "false positives" and 2) without gaps, then the original problem is automatically solved.

But so far no one has found a solution, because there is no algorithm for recognizing such "links" taking into account points 1 and 2 :) Therefore, either drop this idea and look for other ways to combat spam, or formulate your own rules on what to consider links, and from them proceed (for example: "a word, followed by a dot and one of the TLDs", etc). The first path, however, is definitely better.

    I'm a weirdo :)

     $text = 'Lorem ipsum google.com dolor http://www.google.com sit amet https://google.com/'; if(preg_match("/https:\/\/|http:\/\/|[0-9a-z_]+\.[az\/]{2,4}/i", $text)) { //echo 'Match'; $text = preg_replace("/(https:\/\/|http:\/\/|[0-9a-z_]+\.[az\/]{2,4})/i", "<s>$1</s>", $text); } echo $text;