自动从文档中删除联系信息

发布于 2024-10-01 09:22:02 字数 1023 浏览 5 评论 0原文

有谁知道可以从 php 中使用的一个好的解决方案,该解决方案可以有效地从文档中删除电话号码、电子邮件地址甚至联系地址等联系信息?

更新

嘿伙计们,这是我到目前为止的想法,它运行得很好。

function sanitizeContent($content)
    {       
        // emails - even containing white space characters like this 't e s t @ ba d . co m'
        $content = preg_replace('/([A-Za-x-0-9\s\_\.]{1,50})(?=@)@([A-Za-x-0-9\s\_\.]{1,50})/', '[email removed]', $content);       

        // urls
        $content = preg_replace('/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i', '[link removed]', $content);

        // phone numbers            
        $content = preg_replace('/(\d)?(\s|-|.|\/)?(\()?(\d){3}(\))?(\s|-|.|\/){1}(\d){3}(\s|-|.|\/){1}(\d){4}/', '[phone removed]', $content);
        $content = preg_replace('/[0-9\.\-\s\,\/(x|ext)]{5,50}/', '[phone removed]', $content);     

        // addresses????

        return $content;
    }

有没有人对地址有任何想法,我想也许想出一种方法来检测城市、州邮政编码,然后在此之前删除 x 字符。它可能会意外破坏一些数据,但这可能比披露更好。我真的很想听听其他人是否遇到过这个问题。

Does anybody know of a good solution that can be used from php that will effectively remove contact information like phone numbers, email addresses and maybe even contact addresses from a document?

Update

Hey Guys, here is what I came up with so far, it works pretty well.

function sanitizeContent($content)
    {       
        // emails - even containing white space characters like this 't e s t @ ba d . co m'
        $content = preg_replace('/([A-Za-x-0-9\s\_\.]{1,50})(?=@)@([A-Za-x-0-9\s\_\.]{1,50})/', '[email removed]', $content);       

        // urls
        $content = preg_replace('/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i', '[link removed]', $content);

        // phone numbers            
        $content = preg_replace('/(\d)?(\s|-|.|\/)?(\()?(\d){3}(\))?(\s|-|.|\/){1}(\d){3}(\s|-|.|\/){1}(\d){4}/', '[phone removed]', $content);
        $content = preg_replace('/[0-9\.\-\s\,\/(x|ext)]{5,50}/', '[phone removed]', $content);     

        // addresses????

        return $content;
    }

Does anybody have any ideas for addresses, I am thinking maybe come up with a way to detect city, state zip then also strip x chars before that. It could clobber some data accidentally but that might be better than disclosure. I would be really interested to hear if anybody else has run into this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅暮の光 2024-10-08 09:22:02

使用正则表达式。

您可以使用 preg_replace 来完成此操作。

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);

对于电子邮件:

$pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);

对于网址:

Use regular expression.

You can use preg_replace to do it.

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);

for emails:

$pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);

for urls:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文