【问题标题】:Automatically removing contact information from documents自动从文档中删除联系信息
【发布时间】:2010-11-22 16:31:29
【问题描述】:

有没有人知道一个可以从 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 字符。它可能会意外破坏一些数据,但这可能比披露更好。我真的很想知道是否有其他人遇到过这个问题。

【问题讨论】:

  • 你要求的太多了。你必须创造人工智能。
  • 我能想到的最简单的解决方案是开发一组匹配相关数据的正则表达式,并用某种通知替换匹配项(如“联系信息已删除”)。
  • 您需要具体说明要删除的数据。您也无法破解文档中的隐藏频道。
  • 嗯,也许机械土耳其人是要走的路,只是一个想法

标签: php filtering information-hiding


【解决方案1】:

使用正则表达式。

你可以使用 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);

对于网址:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-27
    • 2016-09-23
    • 1970-01-01
    • 2018-08-27
    • 2018-11-28
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多