douyan2970 2011-03-11 00:46
浏览 44
已采纳

php用div替换图像

below is the markup im pulling from my database table. basically i want to replace the image

<img src="http://newvision.co.ug/IM/logo_white_big.gif" width="80" style="background-color:white;padding:1px">

to

<div style='background:url(http://newvision.co.ug/IM/logo_white_big.gif) center center no-repeat;width:40px;height:40px'></div>

I dnt wanna use regular expressions just an htmlparser that ships with php

  <table>
<tbody>
  <tr>
    <td valign="top"><a href="http://newvision.co.ug/PA/8/13/748484" target=
    "_blank"><img src="http://newvision.co.ug/IM/logo_white_big.gif" width="80"
    style="background-color:white;padding:1px" /></a></td>

    <td valign="top">
      <table>
        <tbody>
          <tr>
            <td></td>
          </tr>

          <tr>
            <td valign="top"><b><a target="_blank" href=
            "http://newvision.co.ug/PA/8/13/748484" style="font-size:9pt">The New
            Vision Online : Holland withholds sh10b over CHOGM</a></b></td>
          </tr>

          <tr>
            <td valign="top"><a href="http://newvision.co.ug/PA/8/13/748484" style=
            "font-size:8pt;color&lt;img src=&quot;smilies/worry.gif&quot; alt=&quot;worry&quot; /&gt;ilver"
            target="_blank">http://newvision.co.ug/PA/8/13/748484</a></td>
          </tr>

          <tr>
            <td valign="top" style="font-size:8pt;font-weight:normal">The New Vision
            is Uganda's leading daily newspaper.</td>
          </tr>
        </tbody>
      </table>
    </td>
  </tr>
</tbody>

  • 写回答

1条回答 默认 最新

  • duanlei4759 2011-03-11 00:50
    关注

    There is no parser that ships with PHP, so use PHPQuery, a way of manipulating the DOM in a JQuery like manner instead. This will allow you to use selectors to easily swap out chunks of HTML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路