在mysql表中有这样的字段content,里面的数据如下
"测试数据测[caption id="123" class="capt_1"]<img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]试数据测试数据测试数据测试数据测试数据测试数据"
"测试数据测[caption id="122" class="capt_2"]<img width="110" height="160" src="http://luacloud.com/wp-content/111.png">[/caption]试数据测试数据测试[caption id="121" class="capt_12"]<img width="110" height="200" src="http://luacloud.com/wp-content/123qs.png">[/caption]数据测试数据测试数据测试数据"
"测试数据测试数据测试数据测试数据测试数据测试数据测试数据"
"测试数据测试数据测试数据测试数据测试数据测试数据测试数据"
"测试数据测试数据测试数据测试数据测试数据测试数据测试数据"
如何将字段中的
[caption id="123" class="capt_1"]<img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]
替换为
[caption id="123" class="capt_1"]<a href="http://luacloud.com/wp-content/q.png"></a><img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]
此类的?

解决方案 »

  1.   

    如果格式固定,
    [caption id="123" class="capt_1"]<img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]
    替换为
    [caption id="123" class="capt_1"]<a href="http://luacloud.com/wp-content/q.png"></a><img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]update tt set f1=concat(left(content,instr(content,'<img width="100"')-1),'<a href="http://luacloud.com/wp-content/q.png"></a>',mid(content,instr(content,'<img width="100"'),length(content)))
      

  2.   


    不固定,但是格式是这样的[caption *]<img * src="http://图片地址" /> * [/caption]
    *代表任意字符
    替换成[caption *]<a href="图片的src"></a><img * src="图片地址" /> * [/caption]
      

  3.   

    用程序来实现吧。如果数据只有几万条,则可以在EXCEL中来实现,然后再导回。
      

  4.   

    update tb set content=repalce(content,'[caption id="123" class="capt_1"]<img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]','[caption id="123" class="capt_1"]<a href="http://luacloud.com/wp-content/q.png"></a><img width="100" height="150" src="http://luacloud.com/wp-content/q.png">[/caption]')
      

  5.   

    1条记录只有2个caption?如果不是,用代码循环替换
      

  6.   

    replace() 只能替代一种啊
     所以建议还是导出表后替代在弄回来
     方便