作者harry5438 (证据)
看板PHP
标题[请益] 比较字串困扰
时间Thu Jan 13 13:06:52 2011
弄了几天 还是无解 崩溃了= =
字串比来比去就是有问题...
stopword3.txt
内容如下:
q
w
d
0
10
23
0
0
---
下面是程式码:
<?
//read stoplist
$fp = fopen('stopword3.txt','r');
//$f2p = fopen('stopword2.txt','w');
$stop_count = 0;
while(!feof($fp)){
$stop_count++;
$stoplist[$stop_count] = fgets($fp);
$stoplist[$stop_count] = str_replace("\n","",$stoplist[$stop_count]);
}
fclose($fp);
$ttt = "0";
for($i=1;$i<=$stop_count;$i++){
echo "stopword is :".$stoplist[$i]."<br>";
if(strnatcasecmp($stoplist[$i], $ttt) == 0){
echo "got it ! <br>";
flush();
}
}
?>
----------------------
if(strnatcasecmp($stoplist[$i], $ttt) == 0)
这样写应该没错吧= =
他一直找不到...好烦恼QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.42.21.156
1F:→ bibo9901:你的问题是什麽? 01/13 13:14
2F:→ harry5438:就是stopword档里面有0 可是程式里的if不会过= = 01/13 13:20
3F:推 Jerr:因为除了\n之外 还有\r在eol, 建议str_replace()改用trim() 01/13 13:37
4F:→ harry5438:乾虾! 01/13 13:40
5F:→ JoeHorn:str_replace( PHP_EOL , "" , ..... ) 01/14 00:35