看板 PHP 關於我們 聯絡資訊
※ 引述《wotupset (wotupset)》之銘言: : 我想要將引號中的字變色 : 可是不知道該如何下手 : 例如有個字串; "踢批批" : 要把它替換成: <font color=red>"批踢踢"</font> : 可是我一取代就會兩個一起 : <font color=red>"</font>批踢踢<font color=red>"</font> : 搞到後來只有引號在變色 = = : 可以用正規表示式解決嗎 : 麻煩了...orz 麻煩請貼code 你的雙引號讓人有混亂 你也許是用ereg_replace或preg_replace 這種單純的取代用str_replace就好了 否則只是浪費時間在處理regex的控制字元 而且會比str_replace花時間 : ==== : 註1 : 要是字串很多組: "踢批批" "踢批批" "踢批批" : 這種情況呢?? str_replace會全部都換 就算你是用ereg_replace或preg_replace 印象中也都是預設global replace的 不必特地加上modifier g的樣子 : 註2 : 若引號前面有跳脫字元就不變色 (可以辦到嗎?) : 像是: \"踢批批\" "踢批批" : 出來的結果是: \"踢批批\" <font color=red>"批踢踢"</font> : 不好意思 問題有點多 ....orz str_replace('"踢批批"','<font color="red">"批踢踢"</font>',$s); \"踢批批\"不會被動到啊 red最好用雙引號包住 另外<font>標籤少用 他現在已經被建議不使用了 用<a style="color:#f00;"> -- La vida es pura paison La vida es competicion Allez, Allez, Allez!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 221.169.71.109 ※ 編輯: buganini 來自: 221.169.71.109 (12/10 02:46) ※ 編輯: buganini 來自: 221.169.71.109 (12/10 02:58)