作者buganini (霸格尼尼)
看板PHP
标题Re: [请益] 字串取代的问题
时间Sun Dec 10 02:33:09 2006
※ 引述《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)