duancan9815 2010-09-16 14:17
浏览 43
已采纳

使用Reg Expression重新格式化RSS提要中的图像

I am creating some RSS feeds using PHP (5.2) from a MySQL db specifically for an iPhone app I am making through AppMakr.

They are taken from articles on a website which contain images embedded in them, however in the feeds they don't look great. What I want to try and do is whenever there is an image surround it in <p> so they are on their own line and don't try to wrap around article text.

The format of a image is like this:

 <a rel="lightbox" href="http://images.domain.comk/543/image1.jpg"><img class="imageright" src="http://images.domain.comk/543/image1.jpg" alt="" width="300" height="250" /></a>

So basically surrounded with a <a href> and with a class of "imageright" or "imageleft".

What I would love to change this to is:

 <p><img src="http://images.domain.comk/543/image1.jpg" alt="" width="300" height="250" /></p>

Basically removing the href and imagexxxx class and surrounding in p tags.

I am thinking preg_replace will prob have to be used, but at a loss to what I would actually use for it. Any help is very appreciated.

  • 写回答

2条回答 默认 最新

  • douliao5550 2010-09-16 14:42
    关注

    So you will need to use a regexp for matching like this one:

    <a(.*)><img(.*)class="imageright" (.*)></a>
    

    And then a replace regexp like this:

    <p><img$2$3></p>
    

    This is not the most flexible one but it should do the trick for preg_replace()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答