看板 PHP 關於我們 聯絡資訊
※ 引述《qazsd (nice play!)》之銘言: : 想要取出資料庫裡某個欄位的值 : 且如果遇到某個字元或片段就停出取出 : 例如 "今日諺語:Where there is a will, there is a way. 2007-11-02" : 想要只擷取 "今日諺語:"後面的內容,且若接下來有遇到 2007 就停止取出 : 如果用substr的話 : 就是 substr("今日諺語:Whe...",10) : 但因為要取出的內容不限特定字數 : 所以如果遇到某個片段或字元就停止取出應該是可行 : 只是不知該用什麼函式較好 剛查一下 有蠻多方式的 只是效率上 不知道哪個比較好 = = 順便附上參考網址 自己查查看 way1 沒試過 不知道行不行 用strlen(string) 先計算出 整個句子有多長,然後再扣掉2007-11-02 所佔的數量,就知道要用substr 取幾個了 way2 也是沒試過 stripos(string,find,start) The stripos() function returns the position of the first occurrence of a string inside another string. 就是,找到某特定字串出現的位置,再配合substr做你要做的事 參考網址 http://www.w3schools.com/php/php_ref_string.asp -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.142.192.175
qazsd:感謝 11/04 13:47