作者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