问题描述
|
found。我一直在使用下面的IF PREG_MATCH来区分整个单词和其他单词组成的单词。它突然停止在此脚本以及我使用的任何其他脚本(取决于此命令)中起作用。
结果是它找到了单词的一部分,尽管您可以看到它被明确告知只查找整个单词。
$word = preg_replace(\"/[^a-zA-Z 0-9]+/\",\" \",$word);
if (preg_match(\'#\\b\'.$word.\'\\b#\',$goodfile) && (trim($word) != \"\")) {
$fate = strpos($goodfile,$word);
print $word .\" \";
print $fate .\"</br>\";
解决方法
如果您只想阅读文本文件中一行的第一个单词(如标题所示),请尝试另一种方法:
// Get the file as an array,each element being a line
$lines = file(\"/path/to/file\");
// Break up the first line by spaces
$words = explode(\" \",$lines[0]);
// Get the first word
$firstWord = $words[0];
,这将比爆炸更快,更干净,并且您将不进行任何阵列
$first_word = stristr($lines,\' \',true);