从文本字符串中删除 URL [英] Remove URLs from text string

查看:44
本文介绍了从文本字符串中删除 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 PHP 中搜索和删除字符串中的 URL.这里谈论的是实际文本而不是 HTML.删除示例:

Is it possible to search for and remove URLs from a string in PHP. Talking about the actual text here not the HTML. Example to remove:

mywebsite.com
http://mywebsite.org
www.mywebsite.co.uk
www.my-web-site.net
sub.mywebsite.edu
etc

我的问题是用户提交描述字段并使用它来宣传他们自己的 URL.我不确定它是否可能不会产生太多误报.我想过检测 http://或 www.但这并不能阻止像 mywebsite.com 之类的链接

My issue is users submitting a description field and using it promote their own URLs. I'm not sure if its possible without generating too many false positives. I've thought about detecting the http:// or www. but that doesn't stop links like mywebsite.com

推荐答案

您可以尝试查找 .TLD,其中 TLD 是任何现有的顶级域,但这可能会导致太多误报.

You could try something that looks for .TLD, where TLD is any existing top-level domain, but that may result in too many false positives.

是否有可能实施一个系统,其中包含可疑内容的帖子需要审核才能发布,但其他帖子会立即发布?我假设禁止此类内容是一项严格的业务要求.

Would it be possible to implement a system where posts containing questionable content need moderation to be posted, but others are posted right away? I'm assuming it's a firm business requirement to disallow this type of content.

就我个人而言,我倾向于阻止任何超链接,然后就这样了.但是,这不是我的应用.

Personally, I would tend to just prevent any hyperlinking, and leave it at that. But, it's not my app.

这篇关于从文本字符串中删除 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆