$arr_dictionary=array();
$file_dict_size=filesize("txt\dictionary.txt");
print($file_dict_size);
$file_dict=fopen("txt\dictionary.txt","r");
$dict_buffer=fread($file_dict,$file_dict_size);
fclose($file_dict);
$dict_token=strtok($dict_buffer," ");
print("
".$dict_token."
");
while($dict_token)
{
$dict_key=trim($dict_token);
print($dict_key."
");
$arr_dictionary[$dict_token]=strlen($dict_key);
$dict_token=strtok(" ");
}
上述代码如果dictionary.txt写成下面模式:
a aa aaa b bb bbb c cc ccc fire
则能够正确分解出a aa aaa ....fire
但将dictionary.txt写成如下模式:
a\naa\naaa\nb\nbb\nbbb\nc\ncc\nccc\nfire\n
并分别将调用strtok()时的分隔符改回"\n"
则不能正确分解~~只显示:
a\naa\naaa\nb\nbb\nbbb\nc\ncc\nccc\nfire\n
为什么为这样~~~