我需要使用PHP或JavaScript(最好是PHP)中的字符串中的单词。问题在于,计数必须与Microsoft Word中的工作相同,因为这是人们在他们的参考框架中组装原始文本的地方。 PHP具有单词计数函数(http://php.net/manual/en/function.str-word-count.php)但据我所知,这并不是100%。

有指针吗?

有帮助吗?

解决方案

这里真正的问题是,您正在尝试开发解决方案而不真正理解确切的要求。这并不是一个规格的问题,而是一个问题。

问题的关键是 您的 单词计数算法与 单词计数算法 - 有充分的理由可能是有充分理由的,因为没有明显答案的各种边缘案例需要考虑。因此,您的问题确实应该是“ Word用来计算单词计数的算法?”而且,如果您考虑一下,您已经知道答案 - 它是封闭式的专有软件,因此没有人可以肯定。即使你 处理它,这不是公共接口,因此可以在下一版本中轻松更改它。

基本上,我认为设计软件从根本上是一个坏主意,以便它与您无法完全理解的内容相同的功能。就我个人而言,我将专注于自己开发自己的理智单词, 记录其背后的算法 并证明为什么是 合理的 计算单词的方法(指出没有一种真实的方法)。

如果你 必须 符合Word出于某些短视业务原因的尝试,然后,第一任务是确定他们使用的方法,以便您可以在纸上写下算法。但这并不容易,将很难完全验证,并且有可能在不通知的情况下进行更改...:/

其他提示

sharepoint有一个硬限制为50,000个唯一权限定义每个列表,如果您的组织属于任何重大尺寸或(更有可能)看到重大营业额,那么您将达到该限制。创建自动化解决方案以创建项目级安全性将确保您更快地击中该限制。

的安全性更加复杂,总的路总场地性能较慢,搜索索引也被放缓,并试图在这种情况下管理安全性是噩梦的东西。

它可以完成 >

如果您在SharePoint-Land中陷入了困境,那么您必须创建某种使用自定义CAML查询来调用后端数据的某种自定义前端。哦,然后在列表设置中关闭特定列表的索引,以便在简单的爬网中找不到它们。

以下JS代码给出了67个单词计数。OpenOffice给出了相同的数字。

str = "I need to count words in a string using PHP or Javascript (preferably PHP). The problem is that the counting needs to be the same as it works in Microsoft Word, because that is where the people assemble their original texts in so that is their reference frame. PHP has a word counting function (http://php.net/manual/en/function.str-word-count.php) but that is not 100% the same as far as I know.";

wordCount = str.split(/\s+/g).length;
function countWords( $text )
{
    $text = preg_replace('![^ \pL\pN\s]+!u', '', strtolower($text));
    $text = trim( preg_replace('![ \s]+!u', ' ', $text) );

    $count = count( explode(' ', $text) );

    return $count;
}

您可以将此代码用于单词计数

<title>Untitled Document</title>
<script type="text/javascript" src="mootools.svn.js"></script>
<script type="text/javascript">
    window.addEvent('domready', function()
    {   
        $('myInput').addEvent('keyup', function() 
        {
            max_chars = 0;
            current_value   = $('myInput').value;
            current_length  = current_value.length;
            remaining_chars = max_chars+current_length;
            $('counter_number').innerHTML = remaining_chars;
            if(remaining_chars<=5)
            {
                $('counter_number').setStyle('color', '#990000');
            } else {
                $('counter_number').setStyle('color', '#666666');       
            }   
        }); 
    }); 
</script>

<style type="text/css"> 
    body{
        font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
        font-size:12px;
        color:#000000; 
    }
    a:link, a:visited{color:#0066CC;}
    label{display:block;}
    .counter{
        font-family:Georgia, "Times New Roman", Times, serif;
        font-size:16px; 
        font-weight:bold;
        color:#666666
    } 
</style> 
</head>
<body> 
    <label for="myInput">Write something here:</label> 
    <input type="text" id="myInput" maxlength="20" />  
    <span id="counter_number" class="counter">20</span> 
    Remaining chars

并下载Mootools库...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top