php用div替换图像

时间:2011-03-11 00:46:54

标签: php

下面是我从数据库表中提取的标记。基本上我想替换图像

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

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

我想要使用正则表达式只是一个随PHP附带的htmlparser

  <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 个答案:

答案 0 :(得分:1)

PHP没有解析器,因此请使用PHPQuery,这是一种以类似JQuery的方式操作DOM的方法。这将允许您使用选择器轻松交换HTML块。