doumuyu0837 2012-09-03 14:04
浏览 26
已采纳

整理图像标签

i have this image tag that i'm getting from a weather source that is with errors, the output is not html but wml/wap so it crashes and burns when it shows up. the image tag comes up like this:

<img alt="FACE="Monospace,Courier">LRPatches, Sky clear, Q1020</FONT><Mist, >" src="http://www.vremea.com/images/fogshow.gif"  width="50" height="50"/>

and i would like it to be like this:

<img src="http://www.vremea.com/images/fogshow.gif"  width="50" height="50"/>

i know i have to use preg_replace but I cant seem to make it work, any ideas?

  • 写回答

4条回答 默认 最新

  • dongpu42006096 2012-09-03 14:23
    关注

    This :

    $imgTag = '<img alt="FACE="Monospace,Courier">LRPatches, Sky clear, Q1020</FONT><Mist, >" src="http://www.vremea.com/images/fogshow.gif"  width="50" height="50"/>';
    $returnValue = preg_replace('/(<img)(.*)(src.*)/', '$1 $3',$imgTag);
    

    Will output :

    '<img src="http://www.vremea.com/images/fogshow.gif"  width="50" height="50"/>'
    

    Assuming your malformed <img /> tag doesn't change.

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

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件