[請益] 比較字串困擾

看板PHP作者 (證據)時間15年前 (2011/01/13 13:06), 編輯推噓1(104)
留言5則, 4人參與, 最新討論串1/1
弄了幾天 還是無解 崩潰了= = 字串比來比去就是有問題... 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

01/13 13:14, , 1F
你的問題是什麼?
01/13 13:14, 1F

01/13 13:20, , 2F
就是stopword檔裡面有0 可是程式裡的if不會過= =
01/13 13:20, 2F

01/13 13:37, , 3F
因為除了\n之外 還有\r在eol, 建議str_replace()改用trim()
01/13 13:37, 3F

01/13 13:40, , 4F
乾蝦!
01/13 13:40, 4F

01/14 00:35, , 5F
str_replace( PHP_EOL , "" , ..... )
01/14 00:35, 5F
文章代碼(AID): #1DBeXlR8 (PHP)
文章代碼(AID): #1DBeXlR8 (PHP)