作者tnsshnews (tnsshnews)
看板PHP
标题[请益]请问怎样string replace
时间Wed Oct 5 18:11:48 2011
请问要将下面两行
<wf cmd=ignore pos=IN>of</wf>
<wf cmd=done pos=VBZ ot=notag>is</wf>
取代成
<wf cmd="ignore" pos="IN">of</wf>
<wf cmd="done" pos="VBZ" ot="notag">is</wf>
似乎只用str_replace无法完成, 而且有时=後面的字後面会接空格,
有时候又会是>, 恳请高手赐教!!!
感激不尽
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.109.18.168
1F:→ mervynW:preg_replace('=\ ?') 10/05 18:24
2F:→ tyf99:regex 10/05 18:25
3F:→ tyf99:prematch & postmatch 10/05 18:31
4F:→ tnsshnews:请问要怎样取代呢? 一取代就把中间的属性质都变空了 10/05 22:25
5F:推 mervynW:preg_replace('/(\w+)=\ ?(\w+)/', '\\1="\\2"') 10/05 22:39
6F:→ tnsshnews:谢谢楼上, 好像是取出of与is,没有取代成""? 10/05 23:13
7F:→ tnsshnews:不知道是不是我搞错了, regex真是难懂的东西 10/05 23:14
8F:→ tnsshnews:$string="<wf cmd=ignore pos=IN>for</wf>" 10/05 23:15
9F:→ tnsshnews:preg_replace('/(\w+)=\ ?(\w+)/', '\\1="\\2"',$string 10/05 23:16