我使用textarea在我的網站上寫評論。評論保存在SQLite數據庫中。回車(' n'和' r')未評估爲特殊字符
我的問題是,當我嘗試從數據庫檢索我的評論,以便用<p>
標記替換每個回車標記(在向用戶顯示之前)。
我第一次嘗試nl2br
函數,它工作正常,大量的<br/>
出現在我的代碼。
然後,我已經嘗試:
substr_count($article->texte, '\n');
substr_count($article->texte, '\r');
但返回的結果總是0
。這令我感到驚訝,因爲我認爲nl2br
將取代\n
和\r
字符。
我錯過了什麼嗎?
mb_detect_encoding($article->texte); //returns UTF8
使用雙引號來代替:'substr_count($物品─> texte, 」\ n「); [SUBSTR \ _count不是新生產線的工作?(HTTP的' –
可能重複: //stackoverflow.com/questions/10367971/substr-count-not-working-with-new-lines) –
@AmalMurali非常感謝!這些微妙之處記錄在案嗎?編輯:找到它http://uk.php.net/manual/en/language.types.string.php – Fractaliste