0

: ここでは、Java で単語カウント アルゴリズムを探しているわけではありません。str_word_countPHPソースコードのどこを見つけるか尋ねています。

PHP関数をJavaメソッドとして再作成(可能な場合は1行ずつ)することを検討しています:str_word_count

public class PhpWordCounter {
    public int strWordCount(String str) {
        // The exact algorithm used in PHP's str_word_count here...
        // The str_word_count method takes an optional parameter
        // "format", which, if 0, returns the number of words.
        // This is the portion of the routine that I will actually
        // be mimicking.
    }
}

PHP 5.3.23 のソース コード (tarball) をダウンロードして解凍しました。私は grep しましstr_word_countたが、何も見つかりませんでした。そのため、検索するファイルは言うまでもなく、何を探すべきかさえわかりません。誰かアイデアはありますか? 前もって感謝します!

4

2 に答える 2

2

よく見えるはずです:)最新の安定版ブランチhttp://www.php.net/manual/en/function.str-word-count.phpで利用できるはずです

find . -type f -exec grep -l 'str_word_count' {} \;

./ext/standard/php_string.h
./ext/standard/tests/strings/str_word_count1.phpt
./ext/standard/tests/strings/str_word_count.phpt
./ext/standard/basic_functions.c
./ext/standard/string.c
于 2013-03-19T10:49:09.370 に答える
0

既製の関数があるかどうかはわかりません...しかし、文字列をスペースで分割して配列に分割し、配列の長さを取得します

文字列 vals[] = myString.split("\s+"); int wordCount = vals.length;

于 2013-03-19T10:46:26.280 に答える