开发者

php replace images with divs

开发者 https://www.devze.com 2023-02-15 23:07 出处:网络
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;

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;fo开发者_如何学Cnt-weight:normal">The New Vision
            is Uganda's leading daily newspaper.</td>
          </tr>
        </tbody>
      </table>
    </td>
  </tr>
</tbody>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消