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.

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

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题